roslyn: Microsoft.CodeAnalysis.CodeFixes unable to load the requested types

I’m unable to apply Roslyn code suggestions in dotnet/runtime using the latest bits in main. I tried both in Visual Studio and in VS Code, both fail with different callstacks but they seem to have the same root cause. Are we only importing the references for these assemblies?

I synced runtime to the latest bits from today. This is the dotnet version we’re currently consuming:

$  dotnet --list-sdks

10.0.100-preview.3.25125.5 [C:\Users\calope\source\repos\runtime\.dotnet\sdk]
Visual Studio callstack

Found this in the banner indicating that CSharpUseObjectInitializerCodeFixProvider crashed:

System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeAssembly.get_DefinedTypes()
   at System.Composition.Hosting.ContainerConfiguration.<>c.<WithAssemblies>b__16_0(Assembly a)
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types,AttributedModelProvider attributeContext)
   at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.MefHostExportProvider.Create(String languageName)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key,CreateValueCallback createValueCallback)
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices..ctor(HostLanguageServices hostLanguageServices)
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.Create(HostLanguageServices hostLanguageServices)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key,CreateValueCallback createValueCallback)
   at Microsoft.CodeAnalysis.Shared.Extensions.ProjectExtensions.GetExtendedLanguageServices(Project project)
   at async Microsoft.CodeAnalysis.UseObjectInitializer.AbstractUseObjectInitializerCodeFixProvider`9.FixAsync[TSyntaxKind,TExpressionSyntax,TStatementSyntax,TObjectCreationExpressionSyntax,TMemberAccessExpressionSyntax,TAssignmentStatementSyntax,TLocalDeclarationStatementSyntax,TVariableDeclaratorSyntax,TAnalyzer](<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeFixes.ForkingSyntaxEditorBasedCodeFixProvider`1.FixAllAsync[TDiagnosticNode](<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputePreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass16_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
VS Code callstack

Found this in the Output tab for the official C# extension:

System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeAssembly.get_DefinedTypes()
   at System.Composition.Hosting.ContainerConfiguration.<>c.<WithAssemblies>b__16_0(Assembly a)
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types,AttributedModelProvider attributeContext)
   at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.MefHostExportProvider.Create(String languageName)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key,CreateValueCallback createValueCallback)
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices..ctor(HostLanguageServices hostLanguageServices)
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.Create(HostLanguageServices hostLanguageServices)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key,CreateValueCallback createValueCallback)
   at Microsoft.CodeAnalysis.Shared.Extensions.ProjectExtensions.GetExtendedLanguageServices(Project project)
   at async Microsoft.CodeAnalysis.UseObjectInitializer.AbstractUseObjectInitializerCodeFixProvider`9.FixAsync[TSyntaxKind,TExpressionSyntax,TStatementSyntax,TObjectCreationExpressionSyntax,TMemberAccessExpressionSyntax,TAssignmentStatementSyntax,TLocalDeclarationStatementSyntax,TVariableDeclaratorSyntax,TAnalyzer](<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeFixes.ForkingSyntaxEditorBasedCodeFixProvider`1.FixAllAsync[TDiagnosticNode](<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputePreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass16_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 32 (20 by maintainers)

Most upvoted comments

FYI I still repro this every day. It’s affecting my productivity since I am unable to apply several of the usual Roslyn suggestions, and instead I get the Visual Studio exception banner.

And yes, I also see it in VS Code.

I’d be happy to show you my screen on a call if that can help figure out the root cause.

Most honest answer: because we likely do not have the time/energy/resources to make that happen.

Method ‘get_IsParamsArray’ in type ‘Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol’ from assembly ‘Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=4.8.9.5801, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ does not have an implementation.

That method does seem to have an impl:

Image

Blame puts it in this pr https://github.com/dotnet/roslyn/pull/72390:

Image

Which was made by Aleksey on March 5 2024 (so about a year ago).

So it appears as if it is picking up some version of the analyzers taht is more than a year old? @arunchndr what is our cadence for shipping new releases of analyzers?