question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.Reflection.ReflectionTypeLoadException when getting code actions

See original GitHub issue

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.<SelectManyIterator>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.<ConcatIterator>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.<AppendFixesAsync>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.<CollectCodeFixesActions>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.<GetAvailableCodeActions>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.<Handle>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.<GetFirstNotEmptyResponseFromHandlers>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.<HandleRequestForLanguage>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.<Process>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.<HandleRequest>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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
filipwcommented, Mar 30, 2022

The types needed at runtime are not dictated by OmniSharp but by our dependencies (primarily Roslyn) and any analyzer packages your project would use. The minimal Mono bundled by OmniSharp does not have the full .NET type surface available for size reasons and such missing type errors happen(ed) from time to time. You did not post the full log so I do not known which OmniSharp mode you are running, but judging by the exception I am guessing it is this minimal Mono.

Now that said, this minimal Mono mode (that was used by default so far) is currently deprecated, is no longer maintained and has already been removed in the latest beta version.

Going forward you have two options:

  • install .NET 6 SDK on your machine, and set "omnisharp.useModernNet": true to opt into the most stable and fastest OmniSharp build. This will become the default (see https://github.com/OmniSharp/omnisharp-vscode/issues/5120) in the next release.
  • install the latest Mono Preview, set "omnisharp.useModernNet": false and "omnisharp.useGlobalMono": "always" to run OmniSharp on global Mono

In either case, the full .NET type surface will be available.

0reactions
ArmaanMcleodcommented, Mar 30, 2022

@filipw Thanks for providing this. Unfortunately we can’t really upgrade .NET 6 SDK just yet. Not really a big issue, I can just do code refactoring through VS for the time being.

Would be great if upgrades were more backwards compatible with older .NET versions, since this was working for me not to long ago.

Any chance this could get fixed in an upcoming release or is upgrading the only option?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Get Types in assembly (error: System.Reflection ...
The error message says everything you need, really: try { // your code } catch (ReflectionTypeLoadException ex) { // now look at ex....
Read more >
Unable to load one or more of the requested types. Retrieve ...
Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Read more >
Unable to install windows service application - Reddit
I'm unable to throw/view the system.Reflection.ReflectionTypeLoadException as i lack the source code for this project obviously as it only ...
Read more >
Could not load file or assembly Microsoft.IntelliTrace.Core
I am getting the following exception when running a unit test in a .NET Core 3.0 API project: Message: System.Reflection.ReflectionTypeLoadException ...
Read more >
How to fix System.Reflection.ReflectionTypeLoadException ...
It's seems to be a bug in "Sitecore.EmailCampaign.Activities.dll", since it's compiled with a reference to the assembly "Sitecore.Marketing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found