format icon indicating copy to clipboard operation
format copied to clipboard

`dotnet format` breaks with `System.Reflection.ReflectionTypeLoadException`

Open ArinGhazarian opened this issue 3 years ago • 7 comments

Description

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]

ArinGhazarian avatar Dec 22 '21 20:12 ArinGhazarian

This happens on projects which use Refit v6.2.16 with .NET 5 and dotnet-format 5.1.250801 (even running dotnet build beforehand).

gabrielmaldi avatar Jan 27 '22 02:01 gabrielmaldi

I have the same issue. dotnet format whitespace dotnet format styles all work but not dotnet format --verify-no-changes

ddobbinsweb avatar Mar 24 '22 19:03 ddobbinsweb

Same problem here.

jeffdoolittle avatar Apr 12 '22 23:04 jeffdoolittle

#metoo

timmkrause avatar Apr 13 '22 07:04 timmkrause

Same :(

leo-costa avatar Apr 13 '22 16:04 leo-costa

Same problem here after updating to .NET 7.0.302.

RGalli avatar May 25 '23 13:05 RGalli

Any updates on this? It still has issues when working with source generator in .NET 7.

xyan0001 avatar May 30 '23 02:05 xyan0001