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.TypeLoadException

See original GitHub issue

Issue Description

System.TypeLoadException: Could not load type of field 'Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser:_context' (1) 

Steps to Reproduce

omnisharp instantly reports the issue when starting vscode or restarting omnisharp

OmniSharp log

Starting OmniSharp server at 2019-07-20, 11:07:12 a.m.
    Target: correct_path_to_sln (redacted)

OmniSharp server started with Mono 5.18.1.
    Path: /Users/keeganstothert/.vscode/extensions/ms-vscode.csharp-1.21.0/.omnisharp/1.34.0/omnisharp/OmniSharp.exe
    PID: 95137

System.TypeLoadException: Could not load type of field 'Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser:_context' (1) due to: Could not resolve type with token 01000018 from typeref (expected class 'System.Collections.Generic.Stack`1' in assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51') assembly:netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type:System.Collections.Generic.Stack`1 member:(null)
  at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load (System.Boolean reload) [0x0010b] in <5b0219d367fd4fd68bb5d8e979bb16b3>:0 
  at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load () [0x00000] in <5b0219d367fd4fd68bb5d8e979bb16b3>:0 
  at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor (System.Collections.Generic.IList`1[T] providers) [0x0003b] in <c58a7bdd3f5a468aa1ce25bba6f36889>:0 
  at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build () [0x0003c] in <c58a7bdd3f5a468aa1ce25bba6f36889>:0 
  at OmniSharp.ConfigurationBuilder.Build () [0x00073] in <2a5906ca9ef7486cb9ec80794c73eb10>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_1.<Main>b__1 () [0x000bc] in <8c5dac6e15f8406f96c0166019f5cce3>:0 
  at OmniSharp.CommandLineApplication+<>c__DisplayClass11_0.<OnExecute>b__0 () [0x0000b] in <2a5906ca9ef7486cb9ec80794c73eb10>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00039] in <344a1e8cd6594b17b1e01f8df6ae8827>:0 
  at OmniSharp.CommandLineApplication.Execute (System.Collections.Generic.IEnumerable`1[T] args) [0x00042] in <2a5906ca9ef7486cb9ec80794c73eb10>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00028] in <8c5dac6e15f8406f96c0166019f5cce3>:0 
  at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <2a5906ca9ef7486cb9ec80794c73eb10>:0 

[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

C# log

empty

Environment information

VSCode version: 1.36.1 C# Extension: 1.21.0

Mono Information OmniSharp using global mono :5.18.1
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 2.2.301 Commit: 70d6be0814

Runtime Environment: OS Name: Mac OS X OS Version: 10.14 OS Platform: Darwin RID: osx.10.14-x64 Base Path: /usr/local/share/dotnet/sdk/2.2.301/

Host (useful for support): Version: 3.0.0-preview6-27804-01 Commit: fdf81c6faf

.NET Core SDKs installed: 2.2.301 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview6-27804-01 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
atom-keybindings ms-vscode 3.0.6
code-settings-sync Shan 3.4.0
cpptools ms-vscode 0.24.0
csharp ms-vscode 1.21.0
es7-react-js-snippets dsznajder 2.3.0
hide-gitignored npxms 1.0.1
markdown-all-in-one yzhang 2.4.0
Material-theme zhuangtongfa 2.26.0
msbuild-project-tools tintoy 0.2.55
prettier-vscode esbenp 1.9.0
python ms-python 2019.6.24221
restructuredtext lextudio 113.0.0
rust rust-lang 0.6.1
unity-tools Tobiah 1.1.1
vscode-apollo apollographql 1.7.4
vscode-arduino vsciot-vscode 0.2.27
vscode-eslint dbaeumer 1.9.0
vscode-great-icons emmanuelbeziat 2.1.47
vscode-styled-jsx blanu 1.5.0
vscode-theme-onelight akamud 2.1.0
vscode-typescript-tslint-plugin ms-vscode 1.2.2
write-good-linter travisthetechie 0.1.1

I have tried every step in all similar issues. I have uninstalled and reinstalled mono, unity, dotnet, and vscode. i’ve had similar issues with omnisharp in the past and was able to resolve them with some combination of the above and messing with “omnisharp.path”: “latest”, but this time nothing is working

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
m1stermanagercommented, Jul 22, 2019

downgrading my c# extension to 1.20.0 fixed a similar issue for me on OSX… I was getting an error around System.TypeInitializationException: The type initializer for 'Microsoft.Build.Shared.NativeMethodsShared' threw an exception.

if it seems related enough to this I can re-upgrade and then capture the entire error message but I didn’t have to touch anything w/ mono directly to resolve. just downgrade from 1.20.1 -> 1.20.0

0reactions
pjangamcommented, Aug 3, 2019

Facing same error

Starting OmniSharp server at 3/8/2019, 5:26:12 PM
    Target: *************

OmniSharp server started with Mono 5.20.1.
    Path: /home/pramod/.vscode/extensions/ms-vscode.csharp-1.21.0/.omnisharp/1.34.0/omnisharp/OmniSharp.exe
    PID: 5703

System.TypeInitializationException: The type initializer for 'OmniSharp.MSBuild.Discovery.MSBuildLocator' threw an exception. ---> System.TypeLoadException: Could not find method '.ctor' due to a type load error: Could not load type of field 'System.Collections.Immutable.SortedInt32KeyNode`1+Enumerator[TValue]:s_enumeratingStacks' (0) due to: Could not resolve type with token 01000026 from typeref (expected class 'System.Collections.Generic.Stack`1' in assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51') assembly:netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type:System.Collections.Generic.Stack`1 member:(null) assembly:/home/pramod/.vscode/extensions/ms-vscode.csharp-1.21.0/.omnisharp/1.34.0/omnisharp/System.Collections.Immutable.dll type:Enumerator member:(null)
  at System.Collections.Immutable.ImmutableHashSet`1[T].GetEnumerator () [0x00000] in <6518d0e60ca84f6b915c07341a031a32>:0 
  at System.Collections.Immutable.ImmutableExtensions.GetEnumerableDisposable[T,TEnumerator] (System.Collections.Generic.IEnumerable`1[T] enumerable) [0x00015] in <6518d0e60ca84f6b915c07341a031a32>:0 
  at System.Collections.Immutable.ImmutableHashSet`1[T].Union (System.Collections.Generic.IEnumerable`1[T] other, System.Collections.Immutable.ImmutableHashSet`1+MutationInput[T] origin) [0x00015] in <6518d0e60ca84f6b915c07341a031a32>:0 
  at System.Collections.Immutable.ImmutableHashSet`1[T].Union (System.Collections.Generic.IEnumerable`1[T] items, System.Boolean avoidWithComparer) [0x00034] in <6518d0e60ca84f6b915c07341a031a32>:0 
  at System.Collections.Immutable.ImmutableHashSet`1[T].WithComparer (System.Collections.Generic.IEqualityComparer`1[T] equalityComparer) [0x0001c] in <6518d0e60ca84f6b915c07341a031a32>:0 
  at System.Collections.Immutable.ImmutableHashSet.Create[T] (System.Collections.Generic.IEqualityComparer`1[T] equalityComparer, T[] items) [0x00000] in <6518d0e60ca84f6b915c07341a031a32>:0 
  at OmniSharp.MSBuild.Discovery.MSBuildLocator..cctor () [0x00005] in <3550ddd66d4043539c45cc4b41dec9dc>:0 
   --- End of inner exception stack trace ---
  at OmniSharp.CompositionHostBuilder+<>c__DisplayClass6_0.<CreateDefaultServiceProvider>b__0 (System.IServiceProvider sp) [0x0001c] in <3550ddd66d4043539c45cc4b41dec9dc>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory (Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryCallSite factoryCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) [0x00006] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.IServiceCallSite callSite, TArgument argument) [0x0003a] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped (Microsoft.Extensions.DependencyInjection.ServiceLookup.ScopedCallSite scopedCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) [0x0002d] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton (Microsoft.Extensions.DependencyInjection.ServiceLookup.SingletonCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) [0x0000d] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.IServiceCallSite callSite, TArgument argument) [0x00072] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve (Microsoft.Extensions.DependencyInjection.ServiceLookup.IServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) [0x00000] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass1_0.<RealizeService>b__0 (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) [0x0003e] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) [0x00032] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType) [0x00008] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType) [0x00000] in <824e19d8b53a48d8867d85feb58265d3>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService (System.IServiceProvider provider, System.Type serviceType) [0x00034] in <4b47b422bc4c4615bbdebe1df9b21b0d>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T] (System.IServiceProvider provider) [0x0000e] in <4b47b422bc4c4615bbdebe1df9b21b0d>:0 
  at OmniSharp.CompositionHostBuilder.Build () [0x00082] in <3550ddd66d4043539c45cc4b41dec9dc>:0 
  at OmniSharp.Stdio.Host..ctor (System.IO.TextReader input, OmniSharp.Services.ISharedTextWriter writer, OmniSharp.IOmniSharpEnvironment environment, System.IServiceProvider serviceProvider, OmniSharp.CompositionHostBuilder compositionHostBuilder, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Threading.CancellationTokenSource cancellationTokenSource) [0x00057] in <9d7bd3e1598f4afe8d6ee99159811c4c>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_1.<Main>b__1 () [0x00138] in <5e7b0c1479c34220a9a8ec708a4cc365>:0 
  at OmniSharp.CommandLineApplication+<>c__DisplayClass11_0.<OnExecute>b__0 () [0x0000b] in <3550ddd66d4043539c45cc4b41dec9dc>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00039] in <344a1e8cd6594b17b1e01f8df6ae8827>:0 
  at OmniSharp.CommandLineApplication.Execute (System.Collections.Generic.IEnumerable`1[T] args) [0x00042] in <3550ddd66d4043539c45cc4b41dec9dc>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00028] in <5e7b0c1479c34220a9a8ec708a4cc365>:0 
  at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <3550ddd66d4043539c45cc4b41dec9dc>:0 

[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeLoadException Class (System) - Microsoft Learn
TypeLoadException is thrown when the common language runtime cannot find the assembly, the type within the assembly, or cannot load the type.
Read more >
What could be causing a System.TypeLoadException?
TypeLoadException is thrown when the common language runtime cannot find the assembly, the type within the assembly, or cannot load the type. So ......
Read more >
How a Stupid Mistake Resulted in a System.TypeLoadException
While it compiled without error, I got this exception when I tried to run in: Unhandled Exception: System.TypeLoadException: Could not load type ...
Read more >
System.TypeLoadException - elmah.io
TypeLoadException happens when a type could not be loaded by the CLR. This can be caused by several different issues, but here's a...
Read more >
Type: System.TypeLoadException - GitHub Pages
TypeLoadException is thrown when the Common Language Runtime cannot find the assembly, the type within the assembly, or cannot load the type. TypeLoadException...
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