roslyn: Load roslyn version of the codestyle analyzers to fix torn load state (causes ReflectionTypeLoadException)

Version Used: 4.10.0-3.24175.2+919d4dbfb0dffb35a702417e28ceea652d248bc6

Steps to Reproduce: Trigger CSharpUseCollectionInitializerCodeFixProvider

Expected Behavior:

Fix applied

Actual Behavior:

"Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=4.10.10.15805, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation." string

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 32
  • Comments: 44 (18 by maintainers)

Most upvoted comments

I have this in VS Code since earlier this morning, after I bumped some assets. I think it was the "C# Base language support" extension I bumped, and it’s now on v2.23.15.

It’s pretty intrusive too.

Haven’t analyzed it much, but it breaks commonly used code actions, e.g. Remove unnecessary usings.

Sample:

[Error - 9:56:18 AM] [LanguageServerHost] System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=4.9.10.6718, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Composition.Hosting.ContainerConfiguration.<>c.<WithAssemblies>b__16_0(Assembly a)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`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.GetValueLocked(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.GetValueLocked(TKey key, CreateValueCallback createValueCallback)
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices)
   at Microsoft.CodeAnalysis.RemoveUnnecessaryImports.AbstractRemoveUnnecessaryImportsCodeFixProvider.RemoveUnnecessaryImportsAsync(Document document, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(IProgress`1 progress, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs:line 350
   at Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(IProgress`1 progress, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs:line 304
   at Microsoft.CodeAnalysis.CodeActions.CodeAction.GetOperationsCoreAsync(Solution originalSolution, IProgress`1 progress, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs:line 241
   at Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActionResolveHandler.HandleRequestAsync(CodeAction codeAction, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHandler.cs:line 92
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
System.TypeLoadException: Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=4.9.10.6718, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.

More investigation this morning on this get_IsParamsArray error… I discovered this problem is with the C# extension (I disabled my other C# Dev Kit and related extensions). The problem started happening in the 2.23.15 release. The previous release (2.22.5) doesn’t have the problem, so I’m going to downgrade for now.

I would really like to understand what kind of configuration triggers this issue. And if it is a configuration, I must be very unlucky to be affected on multiple devices and it seems unlikely that a configuration issue has no workaround.

So what configuration do I need to properly use my VS?

PS: I appreciate your effort and time to explain the background of this issue. Please don’t take anything of what I said personal, I am just very annoyed that I can not use many features of VS that I usually use on a daily basis.

I think it’s the use of EnforceCodeStyleInBuild. It tries to load the older version of some analyzers from packages you have loaded into vs, where they don’t abide by these changed interfaces.

If you disable that, we won’t try to load them and things should hopefully be ok

17.11 is out and the issue is still not fixed. What is the ETA?

Same issue here, using latest preview of the C# DevKit (v1.5.14 (pre-release)) and C# v2.26.13 (pre-release). I’m using Apple Silicon, .NET 8.

Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=4.9.10.12906, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Composition.Hosting.ContainerConfiguration.<>c.<WithAssemblies>b__16_0(Assembly a)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`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.GetValueLocked(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.GetValueLocked(TKey key, CreateValueCallback createValueCallback)
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices)
   at Microsoft.CodeAnalysis.RemoveUnnecessaryImports.AbstractRemoveUnnecessaryImportsCodeFixProvider.RemoveUnnecessaryImportsAsync(Document document, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(IProgress`1 progress, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs:line 356
   at Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(IProgress`1 progress, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs:line 310
   at Microsoft.CodeAnalysis.CodeActions.CodeAction.GetOperationsCoreAsync(Solution originalSolution, IProgress`1 progress, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs:line 247
   at Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActionResolveHandler.HandleRequestAsync(CodeAction codeAction, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHandler.cs:line 92
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 150
System.TypeLoadException: Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=4.9.10.12906, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
[Error - 15:16:11] Request codeAction/resolve failed.
  Message: Unable to load one or more of the requested types.
Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=4.9.10.12906, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
  Code: -32000 
[object Object]

@CyrusNajmabadi Yes this was fixed in 17.12

@canselcik See my comment above, I just edited it with a description of how to rollback the C# extension to 2.22.5 which worked for me.

Why is this not listed as a workaround somewhere? It’s fair from ideal, but I can still conditionally enable it for CI builds to enforce clean, no warnings builds.

I posted https://github.com/dotnet/roslyn/issues/72811#issuecomment-2248715193 just as I saw the latest round of comments and noticed that nobody had explicitly posted that on this thread.

fixing it (especially for a payed product) cannot take 4+ month

The fix is not simple. And it will take time to get working.

fixing it (especially for a payed product) cannot take 4+ month

there is no relation on the two. fixes take the time needed to fix them. In this case due to the size and complexity of the fix, that means it takes a while.

–

Fundamentally, the issue is due to your setup loading DLLs that are not compatible with binary changes made in VS. We have no workaround on that until new versions of those DLLs ship that actually work with VS, or we mandate that we will not load dlls from your setup. These are non trivial pieces of work.

I already understood that it is an complex issue. But again: It was done with one release and no quality check was triggered during the release process that basically all “productivity features” are broken.

This is very surprising. And obviously it is not “my setup” loading the wrong dlls, but many people’s setups loading the front dlls.

I understand that there may be no quick fix. But for me (and probably many others) a quite expensive tool lost many of its features.

And it’s not that Microsoft is just a 2 man company that struggles with manpower to maintain VS. And my opinion is still: Breaking a payed product and not fixing it for 4+ month. Especially if going back is not easy and would also require to go back in SDK version etc.

fixing it (especially for a payed product) cannot take 4+ month

The fix is not simple. And it will take time to get working.

fixing it (especially for a payed product) cannot take 4+ month

there is no relation on the two. fixes take the time needed to fix them. In this case due to the size and complexity of the fix, that means it takes a while.

–

Fundamentally, the issue is due to your setup loading DLLs that are not compatible with binary changes made in VS. We have no workaround on that until new versions of those DLLs ship that actually work with VS, or we mandate that we will not load dlls from your setup. These are non trivial pieces of work.

We worked around it by turning off EnforceCodeStyleInBuild for now. dotnet format --verify-no-changes is almost as good for us, and this issue did seem to completely disappear once we did, so I’ve been content with waiting for a fix to be done properly.

This is occurring because CodeGenerationParameterSymbol in the code style layer breaks Roslyn’s rule that the code style layer must only reference public APIs. ISymbol does not allow public implementations:

https://github.com/dotnet/roslyn/blob/0f35ec3b83a0291003bb64fd7b78de0d423d704f/src/Compilers/Core/Portable/Symbols/ISymbol.cs#L22-L23

This type must be removed from the code style layer and/or updated to no longer implement ISymbol.