roslyn-sdk icon indicating copy to clipboard operation
roslyn-sdk copied to clipboard

TypeLoadException when testing analyzer running Roslyn 2.3.2

Open bjornhellander opened this issue 11 months ago • 3 comments

I get this exception when running analyzer tests against Roslyn 2.3.2:

System.TypeLoadException: 'Method 'RegisterOperationBlockStartActionInternal' on type 'CustomAnalysisContextImpl' from assembly 'codeAnalysisProxies_af0f5d57-e957-457a-bcb7-9146cf3acf3b, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a method that is not visible from that assembly.'

Image

I have created a solution using the analyzer template: https://github.com/bjornhellander/RoslynAnalyzerWithV232Problem The tests pass until the last commit where I downgrade the Roslyn packages to version 2.3.2.

Tested with version 1.1.2 of the Microsoft.CodeAnalysis.CSharp.*.Testing packages.

bjornhellander avatar Jan 03 '25 11:01 bjornhellander

This seems to happen with the early 2.x versions of Roslyn

bjornhellander avatar Jan 05 '25 09:01 bjornhellander

These versions of the AnalysisContext class has some internal methods that can not be overridden this way. Would it be enough to only handle the public methods?

bjornhellander avatar Jan 05 '25 09:01 bjornhellander

I'm guessing this is an oversight here? https://github.com/dotnet/roslyn-sdk/blob/102440e23287dd5b5f4598f00fd74aeef8c7b555/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerInfo.cs#L108

sharwell avatar Feb 14 '25 15:02 sharwell