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

.NET SDK 5: Could not load file or assembly Microsoft.CodeAnalysis #878

Closed
kevinoid opened this issue Jan 24, 2022 · 8 comments
Closed

.NET SDK 5: Could not load file or assembly Microsoft.CodeAnalysis #878

kevinoid opened this issue Jan 24, 2022 · 8 comments

Comments

@kevinoid
Copy link

Creating a new issue similar (identical?) to #853, which was closed.

Product and Version Used: Roslynator.Analyzers 4.0.0 and .NET SDK 5.0.404

Steps to Reproduce: Run the following:

dotnet new console
dotnet add package Roslynator.Analyzers --version 4.0.0
dotnet build

Actual Behavior: ~350 CS8032 warnings such as:

CSC : warning CS8032: An instance of analyzer Roslynator.CSharp.Analysis.AbstractTypeShouldNotHavePublicConstructorsAnalyzer cannot be created from /home/username/.nuget/packages/roslynator.analyzers/4.0.0/analyzers/dotnet/cs/Roslynator.CSharp.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.. [/path/to/csproj]

Expected Behavior: No CS8032 warnings.

@josefpihrt
Copy link
Collaborator

Hi,

Thanks for creating new issue.

Roslynator 4.0 requires Roslyn 4.0.1 (Microsoft.CodeAnalysis.dll and others).

To use Roslynator analyzers you need one of following tools:

  • VS 2022 (for diagnostics inside IDE)
  • .NET SDK 6.0 (for diagnostics at command line)

@josefpihrt
Copy link
Collaborator

If you cannot use .NET SDK 6 for some reason you can use Roslynator.Analyzers 3.3.0

@kevinoid
Copy link
Author

Thanks @josefpihrt, that's good to know. My apologies if I missed that in the documentation. I don't suppose there's a way to declare that in the package metadata to give users a more comprehensible error message? If there's nothing to fix here, feel free to close.

@marcospgp
Copy link

marcospgp commented May 16, 2022

So having updated the nuget packages might be why all Roslynator analyzers stopped working for me? Unity is on .NET 4.x, so I'm unable to use the latest release with it?

I'm using Omnisharp with VSCode, latest version, which mentions this in the readme:

image

I'm confused about .NET SDK vs just .NET though :/

I can confirm that reverting Roslynator to 3.3.0 fixed the issue:

image

But I'd of course prefer to stay up to date :(

@sharwell
Copy link
Member

Unity is on .NET 4.x, so I'm unable to use the latest release with it?

Unity doesn't support Roslyn 4.x, but that's completely unrelated to the use of .NET Framework. Roslyn still ships net472 binaries with every build. This restriction is partially mentioned here in the Source Generators section:
https://docs.unity3d.com/2022.2/Documentation/Manual/roslyn-analyzers.html

@marcospgp
Copy link

@sharwell I can't find a reference to Roslyn 4.x support on that Unity docs link, maybe this has since been updated?

@sharwell
Copy link
Member

sharwell commented Oct 3, 2023

@marcospgp It's mentioned indirectly:

Install the Microsoft.CodeAnalysis NuGet package. Your source generator must use Microsoft.CodeAnalysis 3.8 to work with Unity.

Source generators (ISourceGenerator and later IIncrementalGenerator) and analyzers (DiagnosticAnalyzer) are defined in the same assembly, so a version restriction for one implies the same version restriction for the other.

@josefpihrt
Copy link
Collaborator

Roslynator analyzers now supports Roslyn 3.8 (see #1349)

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

No branches or pull requests

4 participants