`dotnet format` breaks with `System.Reflection.ReflectionTypeLoadException`
See original GitHub issueDescription
Similar to https://github.com/dotnet/format/issues/1461, when I try to run dotnet format
on a project that has source generated code, it raises the following error (with full stack-trace):
Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Method not found: 'System.Threading.Tasks.ValueTask`1<Boolean> System.Collections.Generic.IAsyncEnumerator`1.MoveNextAsync()'.
Method 'DisposeAsync' in type 'Subscription' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Method 'MoveNextAsync' in type 'SubscriptionEnumerator' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Method 'MoveNextAsync' in type 'ErrorSubscriptionEnumerator' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Method 'DisposeAsync' in type 'Subscription' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Method 'DisposeAsync' in type 'Subscription' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Method not found: 'System.Threading.Tasks.ValueTask`1<Boolean> System.Collections.Generic.IAsyncEnumerator`1.MoveNextAsync()'.
Method not found: 'System.Threading.Tasks.ValueTask`1<Boolean> System.Collections.Generic.IAsyncEnumerator`1.MoveNextAsync()'.
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()
System.MissingMethodException: Method not found: 'System.Threading.Tasks.ValueTask`1<Boolean> System.Collections.Generic.IAsyncEnumerator`1.MoveNextAsync()'.
System.TypeLoadException: Method 'DisposeAsync' in type 'Subscription' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
System.TypeLoadException: Method 'MoveNextAsync' in type 'SubscriptionEnumerator' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
System.TypeLoadException: Method 'MoveNextAsync' in type 'ErrorSubscriptionEnumerator' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
System.TypeLoadException: Method 'DisposeAsync' in type 'Subscription' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
System.TypeLoadException: Method 'DisposeAsync' in type 'Subscription' from assembly 'HotChocolate.Execution, Version=12.4.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
System.MissingMethodException: Method not found: 'System.Threading.Tasks.ValueTask`1<Boolean> System.Collections.Generic.IAsyncEnumerator`1.MoveNextAsync()'.
System.MissingMethodException: Method not found: 'System.Threading.Tasks.ValueTask`1<Boolean> System.Collections.Generic.IAsyncEnumerator`1.MoveNextAsync()'.
Steps to reproduce
This happens on Strawberry Shake’s demo project which can be easily reproduced. I originally filed an issue here thinking that this was related to Strawberry Shake
but apparently this is a bug in dotnet format
.
Additional Info
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f6213a
Runtime Environment:
OS Name: Mac OS X
OS Version: 11.6
OS Platform: Darwin
RID: osx.11.0-x64
Base Path: /usr/local/share/dotnet/sdk/6.0.101/
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
.NET SDKs installed:
2.2.207 [/usr/local/share/dotnet/sdk]
3.1.101 [/usr/local/share/dotnet/sdk]
5.0.100 [/usr/local/share/dotnet/sdk]
5.0.403 [/usr/local/share/dotnet/sdk]
6.0.100 [/usr/local/share/dotnet/sdk]
6.0.101 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Issue Analytics
- State:
- Created 2 years ago
- Reactions:21
- Comments:7
Top Results From Across the Web
c# - Error message 'Unable to load one or more of the ...
When we keep drilling down the inner exceptions till we see the exception of type ReflectionTypeLoadException and It has a property " ...
Read more >ReflectionTypeLoadException Class (System.Reflection)
Initializes a new instance of the ReflectionTypeLoadException class with the given classes, their associated exceptions, and exception descriptions. Properties ...
Read more >dotnet format command - .NET CLI
The dotnet format command formats code to match EditorConfig settings for the current directory.
Read more >XMLImporter failure - Unable to load one or more of the ...
ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 2> ...
Read more >LoaderException exporting pdf report from web page
Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any updates on this? It still has issues when working with source generator in .NET 7.
Same problem here after updating to .NET 7.0.302.