Issue scanning .net6 Blazor application builds with SonarQube 9.9

We upgraded from v8.9 to v9.9 and started to get this error that breaks the build in Azure DevOps Server with our .net6 Blazor application builds. When SonarQube task is disabled, the build works as expected.

##[debug]Processed: ##vso[task.logdetail id=a522be70-9336-4fe7-8e9b-442f3494577b;parentid=;name=CSC;type=Build;starttime=2023-06-02T01:49:48.6872488Z;state=InProgress;]

##[warning]CSC(0,0): Warning CS8784: Generator 'RazorSourceGenerator' failed to initialize. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.'

##[debug]Processed: ##vso[task.logissue type=Warning;sourcepath=CSC;linenumber=0;columnnumber=0;code=CS8784;]Generator 'RazorSourceGenerator' failed to initialize. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.'

##[debug]Processed: ##vso[task.logdetail id=a522be70-9336-4fe7-8e9b-442f3494577b;parentid=;type=Build;result=Failed;finishtime=2023-06-02T01:49:48.6872488Z;progress=100;state=Completed;parentid=;name=;]

Any ideas on how to fix?

Hi,

Welcome to the community!

Please give us the following version information:

And we’ll need the logs:

  • please give us the verbose output of the scanner commands (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of the BEGIN and END steps)
  • please give the output of running MSBuild in verbose mode (/v:d)

Also, please tell us:

  • what are the commands you are running to do the analysis?
  • are you running all commands from the same folder?

In addition, please see the following guides:

 
Ann

We are also seeing a similar error. with .net 6 and .net 7 projects.

We get the Error

2023-07-21T14:12:39.2806196Z CSC : warning CS8785: Generator ‘RazorSourceGenerator’ failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type ‘MissingMethodException’ with message ‘Method not found: ‘Microsoft.AspNetCore.Razor.Language.RazorConfiguration Microsoft.AspNetCore.Razor.Language.RazorConfiguration.Create(Microsoft.AspNetCore.Razor.Language.RazorLanguageVersion, System.String, System.Collections.Generic.IEnumerable`1<Microsoft.AspNetCore.Razor.Language.RazorExtension>, Boolean)’.’ [*************csproj]

we are using TFS 2018 update 3 with version 4.22 of the TFS Extension
MSBuild version 17.5.1+f6fdcf537 for .NET

Hi @SteveO,

Welcome to the community!

In fact, I’m just realizing that

warning CS8784: Generator 'RazorSourceGenerator'

is unrelated to analysis.

 
Ann

i would normally say that but we dont get the error when we remove the sonarqube extensions from the build. The build happens correctly. We have a number of builds effected by this and it always happens when we include the sonarqube extensions and are building .net 6 or .net 7 applications. As part of the analysis happens during the MSBUILD step (Sonar: (Service.csproj) Project processed successfully - from the build logs) and we are choosing the integration with MSBUILD option then there does appear to be some issue with the extension and MSBUILD when building .net 6 and .net 7 applications.

Also the second line from the original post is the exact same message we are seeing.

1 Like

Hi,

Could you share your full job logs?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Thx,
Ann

8_dotnet build.txt (2.1 MB)
9_Run Code Analysis.txt (277 KB)

With the sonarqube scanner enabled

as i said we don’t get the errors when we disable the sonarqube extensions from TFS

Hi,

Thanks for the logs. I’ve flagged this for the experts in this area.

 
Thx,
Ann

on another note, if you make the scanner standalone and remove the MSbuild integration, the build still works, and the results are posted to the server. it’s an OK work around but sure would be nice to get the MSBUILD integration resolved.

Hello @SteveO,

Do you happen to use the sonar.cs.roslyn.ignoreIssues parameter? We had an issue that we fixed back last year that caused a similar error. That was shipped in the VSTS extension 5.7.0. So, in case you use that parameter, try to update to the latest version of the VSTS extension and the issue should go away.

All the best,
Čaba

1 Like

we did try it with the sonar.cs.roslyn.ignoreIssues but we are using 4.22 extension because we are on tfs 2018.3 your documentation states version 5 of the extension is not compatible with TFS 2018 plus will not install from the VS marketplace as the package is too big. This only started happening once we upgraded to SonarQube 9.9 from 8.9

The version of SonarQube should not affect the behaviour.

Could you try running an analysis with the sonar.cs.roslyn.ignoreIssues parameter set to false?
It should unblock you. My assumption is that you hit the issue I mentioned earlier, which is unfortunately still there if you are using the v4 version of the VSTS extension.

Since the VSTS extension has an embedded version of the scanner for .NET which we cannot update for v4 because of the compatibility issue you mentioned.

Best,
Čaba