dotnet / dotnet/vscode-csharp

System.Reflection.ReflectionTypeLoadException when getting code actions

Open
#5,105 16 comments 3 reactions 0 assignees View on GitHub
Editor-Code Actions OmniSharp
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
18h 40m
Merged PRs (30d)
31

Description

## Environment data
`dotnet --info` output:
```
.NET SDK (reflecting any global.json):
Version: 5.0.406
Commit: 3a48fd6fe5

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.406\

Host (useful for support):
Version: 5.0.15
Commit: 3065735be7

.NET SDKs installed:
3.1.417 [C:\Program Files\dotnet\sdk]
5.0.212 [C:\Program Files\dotnet\sdk]
5.0.406 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
```
VS Code version:
```
1.65.0
b5205cc8eb4fbaa726835538cd82372cc0222d43
x64
```
C# Extension version:
```
v1.24.1
```
## OmniSharp log

```
[fail]: OmniSharp.Stdio.Host
************ Response (11.9941ms) ************
{
"Request_seq": 1259,
"Command": "/v2/getcodeactions",
"Running": true,
"Success": false,
"Message": "\"System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.\\r\\n at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\\r\\n at System.Reflection.RuntimeAssembly.get_DefinedTypes()\\r\\n at System.Linq.Enumerable.d__17`2.MoveNext()\\r\\n at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\\r\\n at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\\r\\n at System.Linq.Enumerable.d__59`1.MoveNext()\\r\\n at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\\r\\n at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\\r\\n at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.LoadFrom(Project project) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 93\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.GetAllCodeFixesForProject(ProjectId projectId) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 57\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.GetSortedCodeFixProviders(Document document) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 156\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.d__13.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.d__12.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 123\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.d__9.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 80\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService.d__1.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\GetCodeActionsService.cs:line 32\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler`2.d__19.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler`2.d__20.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 230\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler`2.d__16.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 131\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Stdio.Host.d__14.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Stdio\\\\Host.cs:line 218\"",
"Body": null,
"Seq": 53207,
"Type": "response"
}
```

## Steps to reproduce

Example Issue is here: https://github.com/Azure/PSRule.Rules.Azure/blob/main/src/PSRule.Rules.Azure/Data/Template/ExpressionHelpers.cs#L218

Where the refactor suggestion is `'if' statement can be simplified [PSRule.Rules.Azure]`.

If you try `Ctrl + .`, it says `No code actions available.`

## Expected behavior

This stopped working recently. Ussually I can refactor with `Ctrl + .` just fine.

## Actual behavior

`No code actions available` message popup.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.