format icon indicating copy to clipboard operation
format copied to clipboard

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

Open OoLunar opened this issue 4 years ago • 31 comments

Version Used: 6.0.2

Steps to Reproduce: Clone https://github.com/OoLunar/Tomoe/commit/f37434a797fa3c8906302989539b9400b1a3b851 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.

OoLunar avatar Mar 07 '22 21:03 OoLunar

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

#error version

sharwell avatar Mar 07 '22 23:03 sharwell

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

OoLunar avatar Mar 08 '22 00:03 OoLunar

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

jcouv avatar Mar 11 '22 00:03 jcouv

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

OoLunar avatar Mar 11 '22 01:03 OoLunar

Might be related to https://github.com/dotnet/format/issues/1519 and/or https://github.com/dotnet/format/issues/1433

You might also want to try the workaround proposed in https://github.com/dotnet/format/issues/1433#issuecomment-1055920818

ranma42 avatar Mar 12 '22 15:03 ranma42

Issue not fixed with https://github.com/dotnet/format/issues/1433#issuecomment-1055920818. Change .NET SDK to 6.0.100 fixed issue for GitHub Actions environment.

guitarrapc avatar Mar 17 '22 01:03 guitarrapc

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]

snebjorn avatar Mar 24 '22 11:03 snebjorn

@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.

sharwell avatar Apr 04 '22 19:04 sharwell

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

OoLunar avatar Apr 04 '22 20:04 OoLunar

@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 https://github.com/dotnet/format/issues/1519#issuecomment-1055922333). Closing this issue as duplicate of https://github.com/dotnet/format/issues/1519

JoeRobich avatar Apr 04 '22 20:04 JoeRobich

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.

nietras avatar Mar 24 '23 11:03 nietras

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

jerohero avatar Mar 28 '23 13:03 jerohero

@jerohero that fixed it for me, thank you.

oakular avatar Apr 05 '23 21:04 oakular

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.

tvanantwerp avatar Apr 27 '23 14:04 tvanantwerp

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?

flobernd avatar Apr 27 '23 20:04 flobernd

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`

manuelesvi avatar May 11 '23 17:05 manuelesvi

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]

ThibautMagnus avatar May 17 '23 19:05 ThibautMagnus

@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?

miroljub1995 avatar Jun 01 '23 20:06 miroljub1995

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.

JoeRobich avatar Jun 01 '23 21:06 JoeRobich

Same for me with .NET 7 SDK

dnaprawa avatar Jun 02 '23 08:06 dnaprawa