6

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)

BlueBSH
  • 291
  • 3
  • 9
  • I'd do these: 1. Restart VS. Still bad? 2. Update VS – tymtam Apr 04 '22 at 23:13
  • 1
    Restarted many times, deleted all the OBJ, .VS and BIN folders, deleted all the %temp% folder files, VS is at the current version 17.1.3, still same warnings... they don't happen on my build server, only on my local VS install too – BlueBSH Apr 04 '22 at 23:49
  • 1
    Are you still using the nuget version of the anlyzers? They were from times before .net 6. Upgrade to true or https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers – stefan.seeland Apr 05 '22 at 14:53
  • EnableNETAnalayzers has been set to true since we moved to .NET6, it's set project wise via a directory.build.props file, searched for any other references to it in projects found none. We do not have any package references to the Microsoft.CodeAnalysis.NetAnalyzers packages left anywhere in project files or build prop/target files that I can find – BlueBSH Apr 05 '22 at 19:17
  • I have a VM with a clean install of VS2022 and cloned my repo to there, and do not get these warnings on that system... it has to be something local, but not sure where to look... I removed all the nuget package caches and nothing helped – BlueBSH Apr 05 '22 at 20:31

5 Answers5

7

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.

Mathieu DSTP
  • 117
  • 3
  • 4
  • Installing the Microsoft.CodeAnalysis.CSharp package solved the warning for me as well. If anyone can elaborate on why this happens... – Enrico Dec 13 '22 at 12:30
2

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.

John
  • 59
  • 4
1

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

Yvonnic
  • 11
  • 1
0

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.

Enrico
  • 2,734
  • 1
  • 27
  • 40
0

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.

Laika
  • 1
  • 1