SergeyTeplyakov / ErrorProne.NET

Set of roslyn-based analyzers for catching common C# errors (inspired by Google's error-prone)
MIT License
869 stars 43 forks source link

Several CodeFixProviders throw MissingMethodException #252

Open tg73 opened 2 years ago

tg73 commented 2 years ago

This is with current head of master f6787c08d76ca761eee3d103f43c4289bbb4d3cb, running in VS 16.11.7. Packaging issue suspected, I'm investigating.

image

System.MissingMethodException : Method not found: 'System.String ErrorProne.NET.StructAnalyzers.ExplicitInParameterAnalyzer.get_DiagnosticId()'.
   at ErrorProne.NET.StructAnalyzers.ExplicitInParameterCodeFixProvider.get_FixableDiagnosticIds()
   at Microsoft.CodeAnalysis.CodeFixes.CodeFixService.GetAndTestFixableDiagnosticIds(CodeFixProvider codeFixProvider)
   at Microsoft.CodeAnalysis.CodeFixes.CodeFixService.<>c.<GetFixableDiagnosticIds>b__37_2(CodeFixProvider f)
   at System.Collections.Immutable.ImmutableInterlocked.GetOrAdd[TKey,TValue](ImmutableDictionary`2& location,TKey key,Func`2 valueFactory)
   at Microsoft.CodeAnalysis.CodeFixes.CodeFixService.<>c__DisplayClass37_0.<GetFixableDiagnosticIds>b__0()
   at Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunction[T](IExtensionManager extensionManager,Object extension,Func`1 function,T defaultValue)
tg73 commented 2 years ago

I've recently been working on an unrelated Roslyn C# code generator. My experience with that, was that the host (be it MSBuild or Visual Studio) would not 'see' any assemblies placed in the same directory as the main analyzer, despite what the online documentation suggests. This was despite working very diligently from various angles on the problem. I do wonder if this is a new behaviour (regression?) in recent VS/MSBuild. In the end, I had to merge all dependencies that might not be available through the host into the analyzer assembly. I used a proprietary tool to embed the assemblies rather than merge them at the IL level. The tool adds a runtime assembly resolver which looks in the analyzer's embedded resources where the unmodified dependency dlls are stored unmodified. This technique might be preferable to merging at the IL level (either with an open source tool or 'by hand' - it's not particularly complicated to do).

I have prodded around a bit with the EP build process, but it's turning into a bit of a rabbit hole which I do not have time for right now. I will try to look at again if and when I have time.