-
Notifications
You must be signed in to change notification settings - Fork 231
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
Fix TypeInitializationException in SymbolStartAnalysisContextWrapper #8991
Fix TypeInitializationException in SymbolStartAnalysisContextWrapper #8991
Conversation
if (symbolStartAnalysisContextType == null) | ||
{ | ||
return static _ => default; | ||
} | ||
var receiverParameter = Parameter(typeof(object)); | ||
return Lambda<Func<object, TProperty>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Lambda()
invocation throws an ArgumentException
if symbolStartAnalysisContextType
is null. That one caused the TypeInitializationException
Quality Gate passedIssues Measures |
Quality Gate passedIssues Measures |
analyzers/src/SonarAnalyzer.CFG/ShimLayer/AnalysisContext/SymbolStartAnalysisContextWrapper.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I had a UT for the fix, but it broke all the other tests because the type initializer is called only once per assembly load.
Out of curiosity, could you share the UT. I would like to see how to reproduce the symbolStartAnalysisContextType
being null
.
@martin-strecker-sonarsource @antonioaversa is there a reason this is draft? Can we merge it? |
Ugly hack, which looked about like this (The // In the UT:
SymbolStartAnalysisContextWrapper.SymbolStartAnalysisContextTypeName = "SomeNonExitingType";
// In the Wrapper
public static string SymbolStartAnalysisContextTypeName = "Microsoft.CodeAnalysis.Diagnostics.SymbolStartAnalysisContext";
// And in the Initializer:
var symbolStartAnalysisContextType = typeof(CompilationStartAnalysisContext).Assembly.GetType(SymbolStartAnalysisContextTypeName); |
I see, ugly indeed, I must say 😆 |
Peach validation: AD0001 is gone: |
Fixes AD0001
See https://cirrus-ci.com/task/5657719948967936?logs=build#L1542
I had a UT for the fix, but it broke all the other tests because the type initializer is called only once per assembly load. I tried with AppDomains, but that didn't work. The only solution would be to isolate the test in a dedicated UT assembly, which does seem to be overkill.