Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S6934 throws AD0001 a lot - SymbolStartAnalysisContextWrapper uncaught exception #9022

Closed
cg110 opened this issue Apr 4, 2024 · 6 comments
Closed
Labels
Type: Bug Exceptions and blocking issues during analysis.

Comments

@cg110
Copy link

cg110 commented Apr 4, 2024

Description

Since upgrading to 9.23.0 and 9.23.1 (I had hoped 9.23.1 would fix this as it's mentioned in the release notes) we've seen an increase in the number of AD0001 from SQ - rules S6934 :
CSC error AD0001: Analyzer 'SonarAnalyzer.Rules.CSharp.SpecifyRouteAttribute' threw an exception of type 'System.TypeInitializationException' with message 'The type initializer for 'SonarAnalyzer.ShimLayer.AnalysisContext.SymbolStartAnalysisContextWrapper' threw an exception.'.
Binary log provides a full stack:

System.TypeInitializationException: The type initializer for 'SonarAnalyzer.ShimLayer.AnalysisContext.SymbolStartAnalysisContextWrapper' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis.VisualBasic, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.CodeAnalysis.VisualBasic, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at SonarAnalyzer.ShimLayer.AnalysisContext.SymbolStartAnalysisContextWrapper..cctor()
   --- End of inner exception stack trace ---
    at lambda_method2(Closure , SymbolStartAnalysisContext )
    at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolStartActions>b__42_0(ValueTuple`2 data)
    at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)

It suggests disabling S6934:
Suppress the following diagnostics to disable this analyzer: S6934
Note that we're using the latest compiler via nuget:
microsoft.net.compilers.toolset 4.9.2

We're seeing this on build servers and locally, with VS 2022 17.9.2 and 17.9.5.

My impression is that it only seems to be in multi-framework dlls, and seems to impact the .net 6, 7 & 8 builds.

Repro steps

It seems to be intermittent, and doesn't happen on every build..

The code it tends to dislike is related to WCF. I'll look into raising a support case if you need full binary logs.

Known workarounds

I'm looking at downgrading to 9.22 or disabling S6934.

Related information

@andrei-epure-sonarsource andrei-epure-sonarsource changed the title 9.23.x rule S6934 throw AD0001 a lot 9.23.x rule S6934 throw AD0001 a lot - SymbolStartAnalysisContextWrapper uncaught exception Apr 5, 2024
@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented Apr 5, 2024

Thanks @cg110 for raising this.

Do you have a small reproducer that could help us?

Otherwise, yes, we'd need the full binary logs.

@andrei-epure-sonarsource andrei-epure-sonarsource changed the title 9.23.x rule S6934 throw AD0001 a lot - SymbolStartAnalysisContextWrapper uncaught exception S6934 throws AD0001 a lot - SymbolStartAnalysisContextWrapper uncaught exception Apr 5, 2024
@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented Apr 5, 2024

Note that we're using the latest compiler via nuget: microsoft.net.compilers.toolset 4.9.2

How are you using this to compile? You are not using the .NET SDK (dotnet build or msbuild)?
Can you share with us how you instrument the compilation with the microsoft.net.compilers.toolset?

Since upgrading to 9.23.0 and 9.23.1 (I had hoped 9.23.1 would fix this as it's mentioned in the release notes) we've seen an increase in the number of AD0001 from SQ

Out of curiosity, what version of SQ are you using?
And what is the version of the Scanner for .NET (MSBuild) that you are using?

@cg110
Copy link
Author

cg110 commented Apr 5, 2024

It's a bit complicated, the compiler nuget is included in every build job, so it's used instead of the sdk one (mainly just trying to keep on top of everything upstream)

We use the 8.0.3 sdk at the moment (8.0.203)

We use the Roslyn analyzer nuget directly in nearly all builds.

We don't use sonar msbuild for most builds as it crippled our build times, so it's used for key branches (main & releases as 99% of the warnings are found by the Roslyn analyzer, and the security ones from sq server are rare to flag anything). I'd have to check the version, it's fairly recent.

I tried to repro it on the file with the problem but it wouldn't do it could be it needs a full build env and use of shared compilation, so the compiler processes are reused.

@cg110
Copy link
Author

cg110 commented Apr 5, 2024

Scanner (when used is 5.14.0) and server is 9.9 as the server is maintained on LTS versions.

@andrei-epure-sonarsource
Copy link
Contributor

Hi @cg110

We weren't able to reproduce this without manually removing the "Microsoft.CodeAnalysis.VisualBasic" DLL from the "microsoft.net.compilers.toolset" NuGet. Because of this, we won't do a fix before SQ 10.5 (to be released next week), because we wouldn't be sure of the underlying problem.

To test a workaround: could you please check if disabling rules S6931 and S6934 from your Quality Profile removes the issue?

Also, we need the binlogs to continue investigation.

  • One way to do that is opening a topic on https://community.sonarsource.com/ and we can send you a private message where you can share them (we devs are replying on the community forum).
  • Otherwise, if you prefer, you can open a support case (slightly more indirection).

Thank you for helping to find this.

@martin-strecker-sonarsource
Copy link
Contributor

Closed as fixed in #9027
#9077 tracks the work to re-enable VB support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

No branches or pull requests

3 participants