CSC : warning CS8032: An instance of analyzer

Hi all,

We are trying to analyse our solutions using SonarQube. Besides using the default SonarScanner C# rules, we have developed a few custom rules using Roslyn SDK specific to our domain and were able to test them locally against our projects.
We are running this on the CI server using Jenkins within Docker containers and since they are being executed within Docker containers, Docker always starts from a fresh image so there should not be any cache related issues.

We tested it against multiple Quality Profiles -

  1. containing only default C# rules,
  2. containing a mix of default C# and custom rules
  3. containing only custom rules

but in case of second quality profile, only the default rules were applied and in case of the third one, none were applied.
We have spent a considerable amount of time to understand and troubleshoot the issue but to no luck.

SonarQube version - Developer edition V7.9.1 (build 27448)
Custom Analysers project -

Visual Studio Enterprise 2017 v15.9.18 used
.NET Standard 2.0 used
Microsoft.CodeAnalysis.dll v1.3.0 used

Roslyn 2.10.0.0 used

Roslyn Plugin Generator v2.0 used

Error logs,

3>CSC : warning CS8032: An instance of analyzer SonarAnalyzer.Rules.CSharp.FrameworkTypeNaming cannot be created from C:\Users\ContainerAdministrator\AppData\Local\Temp.sonarqube\resources\0\SonarAnalyzer.CSharp.dll : Could not load file or assembly ‘Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified… [C:…csproj]

Steps tried for troubleshooting:

  1. Tried using Microsoft.CodeAnalysis.dll v2.2.0 and MSBuild v15.0 - didn’t work
  2. Degraded the version of Microsoft.CodeAnalysis.dll to v1.3.0 (as expected by the error) and MSBuild v14.0 - didn’t work

image

  1. Tried to check the expected versions of Microsoft.CodeAnalysis.dll from other DLLs that are provided by SonarQube like SonarAnalyzer.Security etc. and use the same in our custom analyser project but that also didn’t help.

Hi @dishavirk

Do you use .Net Core to build the project? I’m asking this because we encountered a similar issue with one of our dependencies in the past: https://github.com/dotnet/roslyn/issues/41421

If this is the case the solution is to use the same assembly version of the dependency in all the linked analyzers. On our side we currently use 1.3.2 version.

Please let us know if this solves the problem.

Thank you,
Costin