format: `--fix-analyzers` is broken on .NET 6
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)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 14
- Comments: 25 (8 by maintainers)
Commits related to this issue
- workaround dotnet issue https://github.com/dotnet/format/issues/1433#issuecomment-1055920818 — committed to BoBiene/UA-CloudLibrary by BoBiene 2 years ago
@LorianColtof #1519 was closed and .NET 6.0.202 SDK has been released
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.jsonIf 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@JoeRobich I believe everything for this issue is resolved except for releasing a new version of the global tool on nuget.org.
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 ofdotnet format(without the hyphen).At least this is my understanding of it.
@JoeRobich, I’ve checked out the branch
merges/release/6.x-to-mainand built and installed it.Had the same exception as before:
Repository: https://github.com/TheGreatSageEqualToHeaven/Loretta Commit: 8434c78b8135c5fce3ba984aece3220ca8e96354 Command:
dotnet-format analyzers -v diagOutput: https://gist.github.com/GGG-KILLER/ad4ca56313380584cfe865ef7254cb95@JoeRobich @jmarolf Should this issue be closed now?
@andschwa it should be
I can confirm @JoeRobich 's workaround worked for me:
then