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

Action fails with 'Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.' #1

Open
slaterx opened this issue May 17, 2023 · 5 comments

Comments

@slaterx
Copy link

slaterx commented May 17, 2023

Running the action now fails with error:


2023-05-17T18:07:17.2071746Z Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
2023-05-17T18:07:17.2072170Z Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
2023-05-17T18:07:17.2072190Z 
2023-05-17T18:07:17.2072605Z Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
2023-05-17T18:07:17.2072650Z 
2023-05-17T18:07:17.2072893Z    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
2023-05-17T18:07:17.2073063Z    at System.Reflection.Assembly.GetTypes()
2023-05-17T18:07:17.2073450Z    at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.<>c.<LoadAnalyzersAndFixers>b__0_0(Assembly assembly)
2023-05-17T18:07:17.2073718Z    at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
2023-05-17T18:07:17.2073975Z    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
2023-05-17T18:07:17.2074244Z    at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
2023-05-17T18:07:17.2074506Z    at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
2023-05-17T18:07:17.2074790Z    at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
2023-05-17T18:07:17.2075076Z    at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
2023-05-17T18:07:17.2075486Z    at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.LoadAnalyzersAndFixers(IEnumerable`1 assemblies)
2023-05-17T18:07:17.2075941Z    at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Project project)
2023-05-17T18:07:17.2076315Z    at System.Collections.Immutable.ImmutableDictionary.<>c__DisplayClass9_0`3.<ToImmutableDictionary>b__0(TSource element)
2023-05-17T18:07:17.2076571Z    at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
2023-05-17T18:07:17.2076826Z    at System.Linq.Enumerable.SelectIListIterator`2.MoveNext()
2023-05-17T18:07:17.2077254Z    at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 items, MutationInput origin, KeyCollisionBehavior collisionBehavior)
2023-05-17T18:07:17.2077634Z    at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs, Boolean avoidToHashMap)
2023-05-17T18:07:17.2077913Z    at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs)
2023-05-17T18:07:17.2078566Z    at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 keyComparer, IEqualityComparer`1 valueComparer)
2023-05-17T18:07:17.2079059Z    at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
2023-05-17T18:07:17.2079625Z    at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Solution solution, FormatOptions formatOptions, ILogger logger)
2023-05-17T18:07:17.2080286Z    at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFormatter.FormatAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
2023-05-17T18:07:17.2080974Z    at Microsoft.CodeAnalysis.Tools.CodeFormatter.RunCodeFormattersAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
2023-05-17T18:07:17.2081483Z    at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
2023-05-17T18:07:17.2081932Z    at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
2023-05-17T18:07:17.2082401Z    at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context)
2023-05-17T18:07:17.2082755Z    at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
2023-05-17T18:07:17.2082947Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2083344Z    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseErrorReporting>b__0>d.MoveNext()
2023-05-17T18:07:17.2083515Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2083836Z    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseHelp>b__0>d.MoveNext()
2023-05-17T18:07:17.2084014Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2084360Z    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass21_0.<<UseVersionOption>b__0>d.MoveNext()
2023-05-17T18:07:17.2084535Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2084879Z    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseTypoCorrections>b__0>d.MoveNext()
2023-05-17T18:07:17.2085047Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2085366Z    at System.CommandLine.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__17_0>d.MoveNext()
2023-05-17T18:07:17.2085537Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2085873Z    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseParseDirective>b__0>d.MoveNext()
2023-05-17T18:07:17.2086039Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2086370Z    at System.CommandLine.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__4_0>d.MoveNext()
2023-05-17T18:07:17.2086541Z --- End of stack trace from previous location ---
2023-05-17T18:07:17.2086889Z    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()
2023-05-17T18:07:17.2087421Z System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
2023-05-17T18:07:17.2087432Z 
2023-05-17T18:07:17.2087771Z File name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
2023-05-17T18:07:17.2088292Z  ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
2023-05-17T18:07:17.2088301Z 
2023-05-17T18:07:17.2088583Z File name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
2023-05-17T18:07:17.2089394Z    at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|47_0(NativeAssemblyNameParts* pAssemblyNameParts, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Int32 throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
2023-05-17T18:07:17.2089996Z    at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
2023-05-17T18:07:17.2090395Z    at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
2023-05-17T18:07:17.2090793Z    at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)
2023-05-17T18:07:17.2091107Z    at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
2023-05-17T18:07:17.2091491Z    at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
2023-05-17T18:07:17.2091982Z System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
2023-05-17T18:07:17.2091992Z 
2023-05-17T18:07:17.2092282Z File name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
2023-05-17T18:07:17.2092823Z  ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
2023-05-17T18:07:17.2092830Z 
2023-05-17T18:07:17.2093110Z File name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
2023-05-17T18:07:17.2093861Z    at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|47_0(NativeAssemblyNameParts* pAssemblyNameParts, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Int32 throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
2023-05-17T18:07:17.2094443Z    at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
2023-05-17T18:07:17.2094771Z    at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
2023-05-17T18:07:17.2095172Z    at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)
2023-05-17T18:07:17.2095480Z    at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
2023-05-17T18:07:17.2095862Z    at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

Here's the full pipeline:

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: .NET Lint
    uses: zyactions/dotnet-lint@v1
    with:
        workspace: ./solution.sln
        severity: info
        implicit-restore: true

@flobernd
Copy link
Member

flobernd commented May 17, 2023

Hi, thanks for reporting!

This is a known dotnet-format issue:
dotnet/format#1546

It sadly does not seem like there will be a fix soon (the issue was opened over 1 year ago, closed in the meantime, but now the problem occurs again).

As a workaround, you can remove any <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> directive from your *.csproj files. This seem to work fine according to the comments in the original issue.

@flobernd
Copy link
Member

flobernd commented May 17, 2023

Another workaround is mentioned here:
dotnet/format#1805 (comment)

This involves downgrading the SDK to 7.0.1xx.

@slaterx
Copy link
Author

slaterx commented May 18, 2023

Neither of those worked unfortunately. The hardest part is not knowing what triggers the issue. It started for us out of the blue two days ago...

@flobernd
Copy link
Member

flobernd commented May 18, 2023

@slaterx Would it be possible to share (one of) your *.csproj file(s)? Otherwise it's hard for me to reproduce it. And please paste me the output of dotnet --version executed in the same directory as your solution.

Another option would be to pull the latest standalone version of dotnet-format and use this one instead of the one bundled with the SDK. The bug seems to be fixed upstream. I'm open to add such option to the action.

Edit: The above workaround does not seem to work either.

@flobernd
Copy link
Member

flobernd commented May 19, 2023

@slaterx

The hardest part is not knowing what triggers the issue.

The issue is triggered by a .NET SDK update on the GitHub runner images. They do now ship version 7.0.302 which contains a buggy version of the dotnet-format tools. The most recently working version seems to be 7.0.103.

I published v1.1.0 of the action which introduces the use-standalone-tool input. This can be set to use the standalone version of dotnet-format. The latest version 8.0.426908 contains a bugfix for the issue (but this version is not yet shipped with the current .NET 8 SDK and won't probably get backported to the .NET 7 SDK).

The CI workflow has been adjusted to make use of this option (installs the .NET 8 SDK, installs the latest dotnet-format standalone tool and sets the use-standalone-tool input):
https://github.com/zyactions/dotnet-lint/blob/master/.github/workflows/ci.yml

Note that all other dotnet commands will still honor the global.json and use 7.0.103 (in my case).

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

2 participants