Skip to content
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

Unable to resolve numerous CS8032 warnings #6395

Closed
SoftCircuits opened this issue Jan 1, 2023 · 21 comments
Closed

Unable to resolve numerous CS8032 warnings #6395

SoftCircuits opened this issue Jan 1, 2023 · 21 comments

Comments

@SoftCircuits
Copy link

I am getting numerous CS8032 warnings with .NET 7 and don't seem to be able to solve them.

Severity	Code	Description	Project	File	Line	Suppression State
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Method 'GetCodeBlockAnalyzer' in type 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer' from assembly 'Microsoft.CodeAnalysis.CSharp.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation..	SoftCircuits.Web	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer`1' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	SoftCircuits.Web	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerFieldsAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerFieldsAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	SoftCircuits.Web	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticDescriptorCreationAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticDescriptorCreationAnalyzer`3' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	SoftCircuits.Web	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	SoftCircuits.Web	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer`1' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesDomain	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerFieldsAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerFieldsAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesDomain	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticDescriptorCreationAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticDescriptorCreationAnalyzer`3' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesDomain	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Method 'GetCodeBlockAnalyzer' in type 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer' from assembly 'Microsoft.CodeAnalysis.CSharp.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation..	InsiderArticlesDomain	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesDomain	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer`1' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesManager	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerFieldsAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerFieldsAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesManager	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticDescriptorCreationAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticDescriptorCreationAnalyzer`3' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesManager	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Method 'GetCodeBlockAnalyzer' in type 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer' from assembly 'Microsoft.CodeAnalysis.CSharp.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation..	InsiderArticlesManager	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer cannot be created from C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	InsiderArticlesManager	C:\Users\jwood\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active

Steps To Reproduce

Rebuild All of my solution. Builds without any errors (or, initially, warnings). Then these warnings appear.

Expected behavior

No warnings.

Actual behavior

Warnings.

Additional context

I tried the following:

  1. Updated all NuGet packages.
  2. Upgraded to very latest version of Visual Studio.
  3. Rebooted the machine.
  4. Deleted all Obj and Bin folders.
  5. Upgraded everything from .NET 6 to .NET 7.
  6. Deleted .vs folder.

But the problem persists. I'm not familiar with exactly what the analyzers do. But I don't see anything that says analyzer in the list of installed NuGet packages. This project was working just fine at one point.

@Youssef1313
Copy link
Member

These warnings mention Microsoft.Codeanalysis.Analyzers version 1.1.0, which is very old.

Can you use a more recent version?

@SoftCircuits
Copy link
Author

@Youssef1313 That's strange because this project was only created a year or so ago. Either way, I don't see how to update it. As I indicated, it doesn't appear in the NuGet package manager, and all my NuGet packages are current. This is a black box to me.

@Youssef1313
Copy link
Member

@SoftCircuits Is it possible for you to create a repro project?

@SoftCircuits
Copy link
Author

@Youssef1313 What would be needed for that?

And can I ask how you would update this file? Are you expecting it to appear in the package manager?

@Youssef1313
Copy link
Member

What would be needed for that?

Just upload a project that has this warning. If your current project is closed source or can't be shared, try to reproduce the warning in a new project that you can share.

And can I ask how you would update this file? Are you expecting it to appear in the package manager?

It depends on how you get the analyzer. If it's not an explicit/direct dependency, then you might have a dependency on something that brings Microsoft.CodeAnalysis.Analyzers 1.1.0.

  • You mentioned "This project was working just fine at one point", can you identify the change that caused the warnings?
  • Can you try adding an explicit PackageReference to Microsoft.CodeAnalysis.Analyzers 3.3.3 or 3.3.4-beta1.22559.1?

@SoftCircuits
Copy link
Author

@Youssef1313 Sorry, I was writing a response and lost power (big snowstorm here, on my phone now).

I can try getting the project enough so that I could upload it. It will take me some time.

I added the reference in my main project. It builds fine but still see the warning. (The warnings don't really seem related to the build process.)

I searched my solution for other references to that package but found none.

@Youssef1313
Copy link
Member

Youssef1313 commented Jan 4, 2023

I can try getting the project enough so that I could upload it.

Great. It will help investigating this. Ping me when you get it ready.

@adstep
Copy link

adstep commented Jan 30, 2023

I think there might be some issue with Microsoft.CodeAnalysis.Analyzers. I was hitting this problem running v3.3.4. I downgraded to v3.3.3 and it went away.

@Youssef1313
Copy link
Member

@adstep Can you please provide a repro or a binary log?

@adstep
Copy link

adstep commented Jan 30, 2023

@Youssef1313 what binary log are you looking for?

@Youssef1313
Copy link
Member

@adstep Compile with dotnet build -bl or msbuild SolutionOrProjectFile /bl in a project that reproduces the issue. This will produce an msbuild.binlog file that can help tracking down the issue.

Alternatively, you can upload a project that reproduces the issue.

Note:

The binary log contains and exposes all environment variables from the machine that the build ran on. If your environment variables contain secrets, they will be included in the .binlog file in plaintext.

@adstep
Copy link

adstep commented Jan 30, 2023

@Youssef1313 here's a link to our build logs. The problem occurs when the Microsoft.TestBase.Fabric.ExtendableEnums is using Microsoft.CodeAnalysis.Analyzers 3.3.4.

Here's the warnings I'm seeing.
image

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer cannot be created from C:\Users\adstep\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.3\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.RegisterActionAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.8.6701, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	Microsoft.TestBase.Sample	C:\Users\adstep\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.3\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll	1	Active	System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.RegisterActionAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.8.6701, 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, IEnumerable`1 analyzerTypeNames, Boolean& reportedError)
-----

@mavasani
Copy link
Contributor

@adstep I suspect the root issue here is you have multiple projects in your solution referencing different versions of Microsoft.CodeAnalysis.Analyzers NuGet package - some reference 3.3.3 and some reference 3.3.4. In such a situation, above errors are possible. Are you able to unify all projects in your solution to reference the same version of Microsoft.CodeAnalysis.Analyzers?

@MagicAndre1981
Copy link

@adstep I suspect the root issue here is you have multiple projects in your solution referencing different versions of Microsoft.CodeAnalysis.Analyzers NuGet package

this was my case. The 3.3.3 was a transitive dependency from a different package. So I added 3.3.4 directly to this .net7.0 lib csproj and this warning went away.

@mavasani
Copy link
Contributor

Thanks for the confirmation

@mwasson74
Copy link

Disclaimer: I am new at this

  1. I used the "Analyzer with Code Fix (.NET Standard)" template per the Tutorial: Write your first analyzer and code fix
  2. I updated all NuGet packages
  3. Only 1 project is referencing Microsoft.CodeAnalysis.Analyzers and the version being referenced is 3.3.4 (latest)
  4. I have removed my bin and obj directories for all projects many times
  5. I have also removed all NuGet packages from my machine by deleting everything from %UserProfile%.nuget many times
  6. Still getting "numerous CS8032 warnings":

image

Any guidance would be greatly appreciated.

Thanks,

Matt

@tisis2
Copy link

tisis2 commented Mar 24, 2023

i had the very same issue when i was trying to write my own analyzer in a project that is also using avalonia. i figured out that this issue is only happening because avalonia is using a different version of the analyzer packages than i do... so i tried to reproduce this issue in an isolated project and it was pretty easy to reproduce. i created 2 analyzer project that are using a different package version of the analyzer packages and a project that is using both analyzers.

however, i could not imagine that this use case was not thought of since this would be very common that a consumer uses analyzers of different version... so i thought usually you would not reference an analyzer by project... you would reference a package usually instead... so i packed both analyzers and referenced the packages and then the warnings disappeared.

this issue is really annoying because it stops you from developing a own anaylzer in an environment it is thought to be used, because you arent always in control and in knowledge that you get other analyzers through other dependencies... (like i did with avalonia)

if you are interested in the isolated example you can investigate it here
AnalyzerExamples.zip

@MagicAndre1981
Copy link

you also have this transitive dependency issue. Microsoft.CodeAnalysis.CSharp.Workspaces depends on Microsoft.CodeAnalysis.Analyzers 3.3.3. Add 3.3.4 directly

@tisis2
Copy link

tisis2 commented Mar 30, 2023

this really should not be needed... a package consumer wont always even know that any of his packages ships with an analyzer at all

@MagicAndre1981
Copy link

this is a nuget PackageReference Include issue, that is why I always add all transitive dependencies on my own like we did in the old packages.config days to avoid this.

Microsoft works on showing those dependcies inside VS:

image

maybe this can help to understand version conflicts.

@tisis2
Copy link

tisis2 commented Mar 30, 2023

since this issue does not really happen if you install multiple analyzers via package references but if you install any vie project reference (like i tried to illustrate with my examples above) it seems that nuget itself would resolve the dependencies correctly and solve the version conflict. it seems that the project reference breaks version resolution chain when its used in a analyzer project

as far as i experienced
this works

project <-- package1 <-- packageX(V1)
        <-- package2 <-- packageX(V2)

but this wont

project <-- package1 <-- packageX(V1)
        <-- project2 <-- packageX(V2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants