CS8032 warning with Microsoft.CodeAnalysis out of no where

5.6k Views Asked by At

I've had a solution with a large number of projects in that has built fine since we switched to .NET6 then suddenly I am getting for every project this warning in Visual studio, however it does not appear on the MSBuild output and analyzers are set to run on build. Any idea of how to track down why this is happening? The analyzers are included automatically as part of the fact I am using NET SDK projects with .NET6 so there isn't Nuget package references in he way that I know of?

Warning CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer cannot be created from C:\Users\defaultuser\.nuget\packages\microsoft.codeanalysis.analyzers\3.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..
System.TypeLoadException: Could not load type Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer4 from assembly Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35. at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type) at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.GetAnalyzersForTypeNames(Assembly analyzerAssembly, IEnumerable1 analyzerTypeNames, Boolean& reportedError)

6

There are 6 best solutions below

0
On

Upgrading .net 5-6 on latest VS2022 - solution has been evolving for almost 10 years:

One project that is a dependency for many others was still referencing this nuget package: Microsoft.AspNetCore.Mvc v 2.2.0.

Since it's the most recent version, it didn't stand out as needing to be updated, however was no longer being used anywhere. So, it has flown under the radar, until now.

Removing this nuget package from that project eliminated all my CS8032 warnings.

1
On

I had a similar problem. Running on .net6 but with a transitive nuget dependency on an older version of Microsoft.CodeAnalysis.CSharp.

On my host project, manually adding Microsoft.CodeAnalysis.CSharp latest version (4.4.0 at the time of this writing) did the trick. All CS8032 warnings are gone now.

0
On

My csproj had a package reference to Microsoft.VisualStudio.Web.CodeGeneration.Design Version "6.0.2".

If you go down the rabbit hole you will see that it has a reference to Microsoft.DotNet.Scaffolding.Shared which has a reference to Microsoft.CodeAnalysis.CSharp.

Try removing the package and see if it resolves your issue.

0
On

My issue happened when I added the Microsoft.AspNetCore.Html.Abstractions package to a project that was not the website itself. Caused the errors through the application build.

I was trying to add some HtmlHelper extensions into a library. Decided it wasn't worth it.

Removing the package cleared up everything else.

0
On

I had a similar set of warnings appear due to Microsoft.AspNetCore.Mvc, adding a reference to the "Microsoft.CodeAnalysis.Analyzers" package resolved it.

2
On

As was advised here, I tried to track which dependency is causing the conflict to update it, and tried to override it with explicit reference.

But at the end what turned out to be the problem is that I had two versions of .NET SDK 6.0.x installed on my system. I removed the newer one, and now with only 6.0.302 installed, the problem is gone.

There is probably a more elegant way to solve this issue, tell me if you are aware of one.