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

Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. #1546

Closed
OoLunar opened this issue Mar 7, 2022 · 31 comments

Comments

@OoLunar
Copy link

OoLunar commented Mar 7, 2022

Version Used:
6.0.2

Steps to Reproduce:
Clone OoLunar/Tomoe@f37434a on branch rewrite/DSP_3.0 (Apologies for the non-minimal repro, unsure on how to reproduce)

Expected Behavior:
Successfully formatted <x> files.

Actual Behavior:

[lunar@J-Laptop 03:03:54pm ~/Code/Lunar/Tomoe]$ dotnet format -v diag
  The dotnet runtime version is '6.0.2'.
  The dotnet CLI version is '6.0.200'.
  Using MSBuild.exe located in '/usr/src/dotnet-sdk-6.0.2/sdk/6.0.200/'.
  Formatting code files in workspace '/home/lunar/Code/Lunar/Tomoe/Tomoe.csproj'.
  Loading workspace.
    Determining projects to restore...
  All projects are up-to-date for restore.
  Project Tomoe is using configuration from '/home/lunar/Code/Lunar/Tomoe/.editorconfig'.
  Project Tomoe is using configuration from '/home/lunar/Code/Lunar/Tomoe/Migrations/.editorconfig'.
  Project Tomoe is using configuration from '/home/lunar/Code/Lunar/Tomoe/obj/Debug/net6.0/Tomoe.GeneratedMSBuildEditorConfig.editorconfig'.
  Project Tomoe is using configuration from '/usr/src/dotnet-sdk-6.0.2/sdk/6.0.200/Sdks/Microsoft.NET.Sdk/analyzers/build/config/analysislevel_6_default.editorconfig'.
  Complete in 3209ms.
  Determining formattable files.
  Complete in 778ms.
  Running formatters.
  Running Code Style analysis.
  Determining diagnostics...
  Running 79 analyzers on Tomoe.
  Complete in 4126ms.
  Fixing diagnostics...
  Complete in 5ms.
  Analysis complete in 4131ms.

// This is repeated 253 times.
Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
// End repeat

Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.<>c.<LoadAnalyzersAndFixers>b__0_0(Assembly assembly)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   at System.Collections.Immutable.ImmutableArray.ToImmutableArray[TSource](IEnumerable`1 items)
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.LoadAnalyzersAndFixers(IEnumerable`1 assemblies)
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Project project)
   at System.Collections.Immutable.ImmutableDictionary.<>c__DisplayClass9_0`3.<ToImmutableDictionary>b__0(TSource element)
   at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.SelectIListIterator`2.MoveNext()
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 items, MutationInput origin, KeyCollisionBehavior collisionBehavior)
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs, Boolean avoidToHashMap)
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs)
   at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 keyComparer, IEqualityComparer`1 valueComparer)
   at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Solution solution, FormatOptions formatOptions, ILogger logger)
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFormatter.FormatAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.RunCodeFormattersAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
   at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

// This is repeated 253 times.
System.IO.FileNotFoundException:
File name: 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
// End repeat

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
[lunar@J-Laptop 03:04:04pm ~/Code/Lunar/Tomoe]$

Notes:
Apologies for the non-minimal repro, as I'm not sure what's causing this in the first place. Additional apologies if this belongs in roslyn-analyzers instead of this repo. I didn't see anything related to CAxxxx, so I'm assuming this belongs here.

@sharwell
Copy link
Member

sharwell commented Mar 7, 2022

If you add the following to a .cs file, what version does the compiler report in the error message?

#error version

@OoLunar
Copy link
Author

OoLunar commented Mar 8, 2022

#error: 'version' [Tomoe] csharp(CS1029)
Compiler version: '4.2.0-1.22074.8 (979fa475)'. Language version: 10.0.

@jcouv jcouv transferred this issue from dotnet/roslyn Mar 11, 2022
@jcouv
Copy link
Member

jcouv commented Mar 11, 2022

As a general comment, it may be useful for dotnet format to print out its own version.

@OoLunar
Copy link
Author

OoLunar commented Mar 11, 2022

My apologies, I didn't realize dotnet format had it's own repo. I'll remember next time.

@ranma42
Copy link

ranma42 commented Mar 12, 2022

Might be related to #1519 and/or #1433

You might also want to try the workaround proposed in #1433 (comment)

@guitarrapc
Copy link

Issue not fixed with #1433 (comment).
Change .NET SDK to 6.0.100 fixed issue for GitHub Actions environment.

@snebjorn
Copy link

I'm also getting the ReflectionTypeLoadException - Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp' when running dotnet format.

❯ dotnet format
Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   ...
❯ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.200
 Commit:    4c30de7899

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

Host (useful for support):
  Version: 6.0.2
  Commit:  839cdfb0ec

.NET SDKs installed:
  2.2.401 [C:\Program Files\dotnet\sdk]
  3.1.404 [C:\Program Files\dotnet\sdk]
  5.0.101 [C:\Program Files\dotnet\sdk]
  6.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.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.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.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.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@sharwell
Copy link
Member

sharwell commented Apr 4, 2022

@OoLunar Can you use the Report a Problem feature of Visual Studio to submit a new issue here? In the Additional Attachments section, the item I'm looking for is a binlog, which you can collect by executing a command line build and passing the /bl flag. This will produce an msbuild.binlog file.

@OoLunar
Copy link
Author

OoLunar commented Apr 4, 2022

Unfortunately I cannot do this as I'm on Linux and use Visual Studio Code. Are there any alternatives I can do?

Edit: I failed to read. Will attach the binlog in a moment

@JoeRobich
Copy link
Member

@OoLunar There is a fix coming in the next .NET 6 SDK release. In the meantime you can install dotnet format as a global tool to work around this issue (See #1519 (comment)). Closing this issue as duplicate of #1519

@nietras
Copy link

nietras commented Mar 24, 2023

I am getting this issue but for 4.5.0.0 in .NET 7.0.202.

Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

@jerohero
Copy link

I got the same issue but (temporarily) resolved it by removing <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> from my .csproj.

@oakular
Copy link

oakular commented Apr 5, 2023

@jerohero that fixed it for me, thank you.

@tvanantwerp
Copy link

I got the same issue but (temporarily) resolved it by removing <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> from my .csproj.

This also fixed the problem for me, though I'm not sure why. I don't understand why this would be a problem.

@flobernd
Copy link

flobernd commented Apr 27, 2023

Just encountered the same issue with the .NET 7 SDK while running dotnet-format in a GitHub Action workflow. Any comment from official side here?

@manuelesvi
Copy link

manuelesvi commented May 11, 2023

Same situation here. Does not work in .NET 7.0:

`dotnet --info

.NET SDK:
Version: 7.0.203
Commit: 5b005c19f5

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.203\

Host:
Version: 7.0.5
Architecture: x64
Commit: 8042d61b17

.NET SDKs installed:
6.0.402 [C:\Program Files\dotnet\sdk]
6.0.408 [C:\Program Files\dotnet\sdk]
7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
7.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0-rc.1.22427.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
C:\Users\manchax\source\repos\matrix\global.json

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download`

@ThibautMagnus
Copy link

Same situation here. Does not work in .NET 7.0:

`dotnet --info

Version: 7.0.5
Architecture: x64
Commit: 8042d61b17

.NET SDKs installed:
7.0.203 [C:\Program Files\dotnet\sdk]
7.0.302 [C:\Program Files\dotnet\sdk]

@miroljub1995
Copy link

@JoeRobich we have similar problem (just version is 4.6.0.0 instead of 4.1.0.0) on github actions with 7.0.302 version. Should this issue be reopened?

@JoeRobich
Copy link
Member

The fix for the current SDKs will be in the next servicing release of the SDKs. Sorry the infrastructure that updated the Roslyn version fell behind.

@dnaprawa
Copy link

dnaprawa commented Jun 2, 2023

Same for me with .NET 7 SDK

@ghost
Copy link

ghost commented Jun 2, 2023

We have the same issue in github actions.
The same commit yesterday had passed dotnet format --verify-no-changes, but today it failed with

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.6.0.0, Culture=neutral, PublicKeyToken=31bf3[8](https://github.com/eToro/EtoroOps.Flows/actions/runs/5154865172/jobs/9284376141#step:6:9)56ad364e35'. The system cannot find the file specified.

@jdwholmes
Copy link

+1 for the error @konstantinkos-tr is receiving. Same version(s)

@viktorfallman
Copy link

Same problem as @konstantinkos-tr

@glahaye
Copy link

glahaye commented Jun 2, 2023

Same here, with the same version.

@ffecteau30
Copy link

Same problem as @konstantinkos-tr with same version

@jmpompeo
Copy link

jmpompeo commented Jun 5, 2023

running into the same issue as @konstantinkos-tr with same version

@enriquinho-catalan
Copy link

enriquinho-catalan commented Jun 5, 2023

For those running into this problem. The following worked for me. Use the dotnet-format standalone tool instead of the one bundled into dotnet.

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

Invoke with
dotnet-format

For other versions of dotnet (6, 8, etc). Change the version and source:
ex:

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

This was sufficient for me, you may need to look for a specific version of the tool if this doesn't work for you.

@slonopotamus
Copy link

slonopotamus commented Jun 5, 2023

I switched to Rust and everything worked perfect since then.

On the topic: just wait or use LTS versions of .NET.

@timothyeckert
Copy link

This seems to be broken again in v6.0.423.

@fcl-9
Copy link

fcl-9 commented Jun 18, 2024

This seems to be broken again in v6.0.423.

We start facing the same issue today after installing this NuGet Microsoft.Extensions.Telemetry.Abstractions" Version="8.0.0". We are using same version of the SDK v6.0.423.

@davgia
Copy link

davgia commented Aug 22, 2024

This seems to be broken again in v6.0.423.

We start facing the same issue today after installing this NuGet Microsoft.Extensions.Telemetry.Abstractions" Version="8.0.0". We are using same version of the SDK v6.0.423.

We encounter the same issue after installing System.Diagnostics.DiagnosticSource version 8.0.1. The version of dotnet format is 5.1.250801. We are running GitLab pipelines using the following base image: mcr.microsoft.com/dotnet/sdk:6.0. The command executed is: dotnet format --verify-no-changes $DOTNET_WORKSPACE.

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