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

--fix-analyzers is broken on .NET 6 #1433

Closed
LorianColtof opened this issue Nov 16, 2021 · 25 comments
Closed

--fix-analyzers is broken on .NET 6 #1433

LorianColtof opened this issue Nov 16, 2021 · 25 comments

Comments

@LorianColtof
Copy link

LorianColtof commented Nov 16, 2021

Shows the following error:

Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Microsoft.CodeAnalysis.IIncrementalGenerator' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
...
<some more similar errors>

Steps to reproduce:

mkdir TestProject
cd TestProject
dotnet new console
dotnet new tool-manifest
dotnet tool install dotnet-format
dotnet tool run dotnet-format --fix-analyzers

Tested on .NET 6.0 Debian and Alpine Docker images

EDIT: Also seems to be broken on Windows (tested in 6.0-nanoserver-20H2 Docker image)

@LorianColtof LorianColtof changed the title --fix-analyzers is broken on Linux --fix-analyzers is broken on .NET 6 Nov 16, 2021
@JoeRobich
Copy link
Member

@LorianColtof A newer dotent-format 6.x ships in the .NET 6 SDK. You can read our announcement at #1268.

@LevYas
Copy link

LevYas commented Jan 13, 2022

I have the same issue with the integrated dotnet format on Windows machines.

dotnet format --verify-no-changes
Warnings were encountered while loading the workspace. Set the verbosity option to the 'diagnostic' level to log warnings.
Required references did not load for ... or referenced project. Run `dotnet restore` prior to formatting.
Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Microsoft.CodeAnalysis.Operations.LazyNoneOperation' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.Operations.LazyNoneOperation' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.Operations.LazyAddressOfOperation' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
....
many many more such messages

Doesn't matter if I run it on a clean machine or with an already successfully built project, the result is the same

Is there anything I can do to work around this?
For now, I installed previous version locally and used it, it worked well.

@JoeRobich
Copy link
Member

JoeRobich commented Jan 13, 2022

@LevYas Can you run with the -v diag option set and share the output? Also, is there a repo where we can try and reproduce this behavior?

@LevYas
Copy link

LevYas commented Jan 14, 2022

@JoeRobich I can surely run it with the diag option.
The solution mostly contains class .NET 6 projects, a couple of them use WPF. Also two wapproj projects, one .NET Framework 4.8 project. Some projects use libraries that in turn use Source Generators.
Here's the output https://docs.google.com/document/d/1B7BNelPdpUauz4cfIeuc_mpMXbzUpY0qaTqIEHt4HmU/edit?usp=sharing
The solution was successfully built before the run.
Also, I tried adding to Directory.Build.props NuGet packages with Microsoft.CodeAnalysis, that didn't help.

My project is not open-source, so if the output will not be helpful, we will need to figure something out.

@GGG-KILLER
Copy link

Having the same issue with dotnet-format 7.0.306301+be830633005691db3de633dd24acc6e25c17eae4, here's the output with -v diag:
https://gist.github.com/GGG-KILLER/055ca60eebdeb3bcdda9743ea55f29c0

Here's the repository: https://github.com/GGG-KILLER/Loretta

@matteus6007
Copy link

I had the same issue when running command:

dotnet-format --fix-analyzers

Seems to work if you use the following:

dotnet format analyzers

@GGG-KILLER
Copy link

The issue in my case is running dotnet-format analyzers

@marleypowell
Copy link

I think this is related to #23972

@GGG-KILLER
Copy link

Hello @JoeRobich has there been any progress in this?

I've been trying to use the PublicAPI analyzer together with some source generators and this bug is making the PublicAPI analyzer unusable since I can't use code fixes from the VS UI.

@JoeRobich
Copy link
Member

@GGG-KILLER Your issue is resolved in the latest 6.x builds. Need to get the main branch updated with #1473 before the 7.x build is working.

@GGG-KILLER
Copy link

@GGG-KILLER Your issue is resolved in the latest 6.x builds. Need to get the main branch updated with #1473 before the 7.x build is working.

Oh ok, thank you! I'll give it a try then!

@GGG-KILLER
Copy link

@JoeRobich, I've checked out the branch merges/release/6.x-to-main and built and installed it.

Had the same exception as before:

Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

Repository: https://github.com/TheGreatSageEqualToHeaven/Loretta
Commit: 8434c78b8135c5fce3ba984aece3220ca8e96354
Command: dotnet-format analyzers -v diag
Output: https://gist.github.com/GGG-KILLER/ad4ca56313380584cfe865ef7254cb95

@JoeRobich
Copy link
Member

@GGG-KILLER When you run dotnet --info what SDK is being resolved?

@GGG-KILLER
Copy link

GGG-KILLER commented Feb 28, 2022

@GGG-KILLER When you run dotnet --info what SDK is being resolved?

The SDK being resolved is 7.0.0-preview.1.22076.8:

dotnet --info output
.NET SDK (reflecting any global.json):
Version:   7.0.100-preview.1.22110.4
Commit:    129d2465c8

Runtime Environment:
OS Name:     Windows
OS Version:  10.0.19041
OS Platform: Windows
RID:         win10-x64
Base Path:   C:\Program Files\dotnet\sdk\7.0.100-preview.1.22110.4\

Host (useful for support):
Version: 7.0.0-preview.1.22076.8
Commit:  405337939c

.NET SDKs installed:
3.1.200-preview-014883 [C:\Program Files\dotnet\sdk]
3.1.416 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
5.0.405 [C:\Program Files\dotnet\sdk]
6.0.100-preview.4.21255.9 [C:\Program Files\dotnet\sdk]
6.0.100-preview.5.21302.13 [C:\Program Files\dotnet\sdk]
6.0.100-preview.7.21379.14 [C:\Program Files\dotnet\sdk]
6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk]
6.0.100 [C:\Program Files\dotnet\sdk]
6.0.101 [C:\Program Files\dotnet\sdk]
6.0.200 [C:\Program Files\dotnet\sdk]
7.0.100-preview.1.22110.4 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0-preview.5.21301.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0-preview.7.21378.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-preview.1.22109.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0-preview.5.21301.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0-preview.7.21377.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-preview.1.22076.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-preview.5.21301.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-preview.7.21378.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-rc.1.21451.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0-preview.1.22077.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

EDIT: I'll test with a .NET 6 container, just a second.
EDIT2: Tested in a .NET 6 container with the image mcr.microsoft.com/dotnet/sdk:6.0 and it also failed.

@JoeRobich
Copy link
Member

JoeRobich commented Mar 1, 2022

@GGG-KILLER Thanks for the updates. Upon reviewing the changes in the release/6.x branch we were still behind the 6.0.200 SDK. I've been busy getting the channel subscriptions updated.

Task list:

cc: @jmarolf

@JoeRobich
Copy link
Member

A workaround until new SDKs are released would be to install dotnet-format as a global tool and invoke it with dotnet-format (the hyphen is important).

If you are only using .NET 6 SDKs:
dotnet tool install -g dotnet-format --version "6.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json

If you are previewing .NET 7 SDKs:
dotnet tool install -g dotnet-format --version "7.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json

@GGG-KILLER
Copy link

A workaround until new SDKs are released would be to install dotnet-format as a global tool and invoke it with dotnet-format (the hyphen is important).

If you are only using .NET 6 SDKs: dotnet tool install -g dotnet-format --version "6.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json

If you are previewing .NET 7 SDKs: dotnet tool install -g dotnet-format --version "7.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json

I've installed the version for .NET 7 SDKs and can confirm it is working now. Thank you very much!

@Meligy
Copy link

Meligy commented Mar 2, 2022

Am I reading the last comment right, that there will be no fix in an upcoming .NET 6.x SDK (like some upcoming 6.0.300 SDK) and it'll be only in .NET 7?

@GGG-KILLER
Copy link

GGG-KILLER commented Mar 3, 2022

Am I reading the last comment right, that there will be no fix in an upcoming .NET 6.x SDK (like some upcoming 6.0.300 SDK) and it'll be only in .NET 7?

What @JoeRobich said was that while a new version of .NET 6 or .NET 7 (whichever you're using) isn't released (with the fix for this issue), you can use the commands they've provided to get a version of dotnet-format with the fix.
Do note that with the version installed through those commands, you'll need to call dotnet-format (with the hyphen!) instead of dotnet format (without the hyphen).

At least this is my understanding of it.

@justinmchase
Copy link

I can confirm @JoeRobich 's workaround worked for me:

dotnet tool install -g dotnet-format --version "6.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json

then

dotnet-format -v

@jmarolf
Copy link
Contributor

jmarolf commented Mar 10, 2022

@JoeRobich I believe everything for this issue is resolved except for releasing a new version of the global tool on nuget.org.

@andyleejordan
Copy link
Member

Do we now if the fix will be in SDK 6.0.202? I used the provided workaround for now to run it manually (loving dotnet format!) but want to integrate it into CI ASAP.

@ciastooo
Copy link

@andschwa it should be

BoBiene added a commit to BoBiene/UA-CloudLibrary that referenced this issue Mar 25, 2022
@ciastooo
Copy link

@LorianColtof #1519 was closed and .NET 6.0.202 SDK has been released

@glen-84
Copy link

glen-84 commented May 22, 2023

@JoeRobich @jmarolf Should this issue be closed now?

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