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.

omnisharp-vscode version 1.24.3 does not load on debian (possibly other OS'es)

See original GitHub issue

Issue Description

Version 1.24.3 of the extension fails to load, throwing an TypeLoadException with message

Could not load type of field ‘Roslynator.Host.Mef.MefHostServices:_compositionContext’ (2) due to: Could not load file or assembly ‘System.Composition.Runtime, Version=1.0.31.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. at (wrapper managed-to-native) System.RuntimeType.GetPropertiesByName_native(System.RuntimeType,intptr,System.Reflection.BindingFlags,System.RuntimeType/MemberListType) … more stack frames in OmniSharp log below

Steps to Reproduce

Use docker base image mcr.microsoft.com/dotnet/sdk:6.0.201 for the dev container then specify the extension in devcontainer.json for the dev container. After VS Code has connected to the dev container it attempts to install the extension which fails with a TypeLoadException.

Using the docker base image with the .NET SDK ensures that no other .NET SDKs or .NET runtimes are installed in the environment. For investigation and/or testing, I believe this could be critical.

Expected Behavior

Version 1.24.3 of the extension loads without exception

Actual Behavior

Version 1.24.3 throws TypeLoadException when being installed/loaded by VS Code. All functionality is broken, in particular code actions.

Logs

OmniSharp log

Starting OmniSharp server at 4/2/2022, 9:12:28 PM Target: /src/Backend.sln

OmniSharp server started. Path: /home/dev/.vscode-server/extensions/ms-dotnettools.csharp-1.24.3-linux-x64/.omnisharp/1.38.2/run PID: 1700

    Starting OmniSharp on debian 11.0 (x64)
    Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
    Using the 'dotnet' on the PATH.
    DotNetPath set to dotnet
    Located 1 MSBuild instance(s)
        1: StandAlone 17.1.1 - "/home/dev/.vscode-server/extensions/ms-dotnettools.csharp-1.24.3-linux-x64/.omnisharp/1.38.2/omnisharp/.msbuild/Current/Bin"
    MSBUILD_EXE_PATH environment variable set to '/home/dev/.vscode-server/extensions/ms-dotnettools.csharp-1.24.3-linux-x64/.omnisharp/1.38.2/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
    Registered MSBuild instance: StandAlone 17.1.1 - "/home/dev/.vscode-server/extensions/ms-dotnettools.csharp-1.24.3-linux-x64/.omnisharp/1.38.2/omnisharp/.msbuild/Current/Bin"
        CscToolExe = csc.exe
        MSBuildToolsPath = /home/dev/.vscode-server/extensions/ms-dotnettools.csharp-1.24.3-linux-x64/.omnisharp/1.38.2/omnisharp/.msbuild/Current/Bin
        CscToolPath = /home/dev/.vscode-server/extensions/ms-dotnettools.csharp-1.24.3-linux-x64/.omnisharp/1.38.2/omnisharp/.msbuild/Current/Bin/Roslyn
        BypassFrameworkInstallChecks = true
        MSBuildExtensionsPath = /home/dev/.vscode-server/extensions/ms-dotnettools.csharp-1.24.3-linux-x64/.omnisharp/1.38.2/omnisharp/.msbuild

System.TypeLoadException: Could not load type of field ‘Roslynator.Host.Mef.MefHostServices:_compositionContext’ (2) due to: Could not load file or assembly ‘System.Composition.Runtime, Version=1.0.31.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. at (wrapper managed-to-native) System.RuntimeType.GetPropertiesByName_native(System.RuntimeType,intptr,System.Reflection.BindingFlags,System.RuntimeType/MemberListType) at System.RuntimeType.GetPropertiesByName (System.String name, System.Reflection.BindingFlags bindingAttr, System.RuntimeType+MemberListType listType, System.RuntimeType reflectedType) [0x0001b] in <533173d24dae460899d2b10975534bb0>:0 at System.RuntimeType.GetPropertyCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Type[] types, System.Boolean allowPrefixLookup) [0x00010] in <533173d24dae460899d2b10975534bb0>:0 at System.RuntimeType.GetProperties (System.Reflection.BindingFlags bindingAttr) [0x00000] in <533173d24dae460899d2b10975534bb0>:0 at System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties (System.Type type) [0x00014] in <533173d24dae460899d2b10975534bb0>:0 at System.Composition.TypedParts.Discovery.TypeInspector+<DiscoverPropertyExports>d__7.MoveNext () [0x00037] in <2d4bd81b7fea479cb0a52f844b6edf97>:0 at System.Composition.TypedParts.Discovery.TypeInspector+<DiscoverExports>d__5.MoveNext () [0x000db] in <2d4bd81b7fea479cb0a52f844b6edf97>:0 at System.Composition.TypedParts.Discovery.TypeInspector.InspectTypeForPart (System.Reflection.TypeInfo type, System.Composition.TypedParts.Discovery.DiscoveredPart& part) [0x00061] in <2d4bd81b7fea479cb0a52f844b6edf97>:0 at System.Composition.TypedParts.TypedPartExportDescriptorProvider…ctor (System.Collections.Generic.IEnumerable1[T] types, System.Composition.Convention.AttributedModelProvider attributeContext) [0x00037] in <2d4bd81b7fea479cb0a52f844b6edf97>:0 at System.Composition.Hosting.ContainerConfiguration.CreateContainer () [0x00042] in <2d4bd81b7fea479cb0a52f844b6edf97>:0 at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create (System.Collections.Generic.IEnumerable1[T] assemblies) [0x00031] in <f78fde32b7b244ca95ad9f75f5377ae7>:0 at OmniSharp.HostServicesAggregator.CreateHostServices () [0x00000] in <407751de6f434a52aa536ffcf396059d>:0 at OmniSharp.OmniSharpWorkspace…ctor (OmniSharp.HostServicesAggregator aggregator, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, OmniSharp.FileWatching.IFileSystemWatcher fileSystemWatcher) [0x00046] in <407751de6f434a52aa536ffcf396059d>:0 at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,System.Composition.Hosting.Core.LifetimeContext,System.Composition.Hosting.Core.CompositionOperation) at System.Composition.TypedParts.ActivationFeatures.DisposalFeature+<>c__DisplayClass0_0.<RewriteActivator>b__0 (System.Composition.Hosting.Core.LifetimeContext c, System.Composition.Hosting.Core.CompositionOperation o) [0x00000] in <2d4bd81b7fea479cb0a52f844b6edf97>:0 at System.Composition.Hosting.Core.LifetimeContext.GetOrCreate (System.Int32 sharingId, System.Composition.Hosting.Core.CompositionOperation operation, System.Composition.Hosting.Core.CompositeActivator creator) [0x000a8] in <db7a9e9ce8f2483abd2dba005db8e856>:0 at System.Composition.TypedParts.ActivationFeatures.LifetimeFeature+<>c__DisplayClass1_0.<RewriteActivator>b__0 (System.Composition.Hosting.Core.LifetimeContext c, System.Composition.Hosting.Core.CompositionOperation o) [0x00011] in <2d4bd81b7fea479cb0a52f844b6edf97>:0 at System.Composition.Hosting.Core.CompositionOperation.Run (System.Composition.Hosting.Core.LifetimeContext outermostLifetimeContext, System.Composition.Hosting.Core.CompositeActivator compositionRootActivator) [0x00022] in <db7a9e9ce8f2483abd2dba005db8e856>:0 at System.Composition.Hosting.Core.LifetimeContext.TryGetExport (System.Composition.Hosting.Core.CompositionContract contract, System.Object& export) [0x0001d] in <db7a9e9ce8f2483abd2dba005db8e856>:0 at System.Composition.Hosting.CompositionHost.TryGetExport (System.Composition.Hosting.Core.CompositionContract contract, System.Object& export) [0x00000] in <db7a9e9ce8f2483abd2dba005db8e856>:0 at System.Composition.CompositionContext.GetExport (System.Composition.Hosting.Core.CompositionContract contract) [0x00000] in <9222e906419e4f47bc57ced5ad91678c>:0 at System.Composition.CompositionContext.GetExport (System.Type exportType, System.String contractName) [0x00008] in <9222e906419e4f47bc57ced5ad91678c>:0 at System.Composition.CompositionContext.GetExport[TExport] (System.String contractName) [0x00000] in <9222e906419e4f47bc57ced5ad91678c>:0 at System.Composition.CompositionContext.GetExport[TExport] () [0x00000] in <9222e906419e4f47bc57ced5ad91678c>:0 at OmniSharp.Stdio.Host.Initialize () [0x0000d] in <2584067dfcea42a69c19a025cfbc4799>: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) [0x0007b] in <2584067dfcea42a69c19a025cfbc4799>:0 at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_1.<Main>b__1 () [0x0017d] in <1b91b6472b674f53a4fe2ae232ca9859>:0 at OmniSharp.CommandLineApplication+<>c__DisplayClass12_0.<OnExecute>b__0 () [0x0000b] in <3d93fabea6954f4ba147450b0cf4332a>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication+<>c__DisplayClass146_0.<OnExecute>b__0 (System.Threading.CancellationToken _) [0x00000] in <abe0fc6797a94a73931eea5cecaffd78>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync (System.String[] args, System.Threading.CancellationToken cancellationToken) [0x000bf] in <abe0fc6797a94a73931eea5cecaffd78>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00016] in <abe0fc6797a94a73931eea5cecaffd78>:0 at OmniSharp.CommandLineApplication.Execute (System.String[] args) [0x00081] in <3d93fabea6954f4ba147450b0cf4332a>:0 at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00028] in <1b91b6472b674f53a4fe2ae232ca9859>:0 at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <3d93fabea6954f4ba147450b0cf4332a>:0

C# log

Post the output from Output-->C# here: The C# log is empty, no output

Environment information

VSCode version: 1.66.0 C# Extension: 1.24.3

Mono Information OmniSharp using built-in mono
Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.201 Commit: ef40e6aa06

Runtime Environment: OS Name: debian OS Version: 11 OS Platform: Linux RID: debian.11-x64 Base Path: /usr/share/dotnet/sdk/6.0.201/

Host (useful for support): Version: 6.0.3 Commit: c24d9a9c91

.NET SDKs installed: 6.0.201 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

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

Visual Studio Code Extensions
Extension Author Version
csharp ms-dotnettools 1.24.3
docomment k–kato 0.1.30
dotnet-test-explorer formulahendry 0.7.7
EditorConfig EditorConfig 0.16.4
gitlens eamodio 12.0.5
markdown-preview-enhanced shd101wyy 0.6.2
powershell ms-vscode 2021.12.0
roslynator josefpihrt-vscode 4.1.0
vscode-solution-explorer fernandoescolar 0.4.5

Additional Information/Observations

As a result of this extension not loading the C# related features no longer work. For example F2 to rename an identifier does not work. Selecting any element then trying code actions with Ctrl+. results in message “No code actions available”.

When I revert to version 1.24.1 of this extensions all works fine. Also checked version 1.24.2 which shows the same problem. Based on my experiments it appears as if this issue was absent in version 1.24.1 and introduced with version 1.24.2.

More details about my set up:

  • Windows 10 Pro version 10.0.19044 Build 1044
  • WSL2 with distro Ubuntu 20.04
  • Docker Desktop version 4.3.2
  • Dev container with base image mcr.microsoft.com/dotnet/sdk:6.0.201

I also tested with base image mcr.microsoft.com/dotnet/sdk:6.0.102. The observation remains the same.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
filipwcommented, Apr 3, 2022

This manifests itself, I assume, only on the embedded Mono variant of OmniSharp. It is deprecated and will be removed in the next release.

Things should work correctly on the .NET 6.0 build of OmniSharp which you can enable by setting "omnisharp.useModernNet":true

2reactions
ghidalgo3commented, Apr 4, 2022

Adding "OmniSharp.useModenNet": true also resolved an exception on macOS that completely broke OmniSharp at startup.

For reference, this is the exception:

mniSharp server started.
    Path: /Users/gustavo/.vscode/extensions/ms-dotnettools.csharp-1.24.3/.omnisharp/1.38.3-beta.31/run
    PID: 50269

System.TypeInitializationException: The type initializer for 'System.ComponentModel.TypeDescriptor' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Interop+Sys.GetNonCryptographicallySecureRandomBytes(byte*,int)
  at Interop.GetRandomBytes (System.Byte* buffer, System.Int32 length) [0x00000] in <ba70b91736bd40cb990a357097dba9c3>:0 
  at System.Guid.NewGuid () [0x00000] in <ba70b91736bd40cb990a357097dba9c3>:0 
  at System.ComponentModel.TypeDescriptor..cctor () [0x00034] in <bc69ad8632744cfba18f9705e53c6302>:0 
   --- End of inner exception stack trace ---
  at OmniSharp.Internal.CommandOptionExtensions.GetValueOrDefault[T] (McMaster.Extensions.CommandLineUtils.CommandOption opt, T defaultValue) [0x00008] in <b81453133ee74092816142afbffb5d49>:0 
  at OmniSharp.Stdio.StdioCommandLineApplication.get_Encoding () [0x00000] in <ff89c28654c64c08be0af235972b4254>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_1.<Main>b__1 () [0x00000] in <4061e52126604f67b6d455853ab7baf7>:0 
  at OmniSharp.CommandLineApplication+<>c__DisplayClass12_0.<OnExecute>b__0 () [0x0000b] in <b81453133ee74092816142afbffb5d49>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication+<>c__DisplayClass146_0.<OnExecute>b__0 (System.Threading.CancellationToken _) [0x00000] in <abe0fc6797a94a73931eea5cecaffd78>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync (System.String[] args, System.Threading.CancellationToken cancellationToken) [0x000bf] in <abe0fc6797a94a73931eea5cecaffd78>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00016] in <abe0fc6797a94a73931eea5cecaffd78>:0 
  at OmniSharp.CommandLineApplication.Execute (System.String[] args) [0x00081] in <b81453133ee74092816142afbffb5d49>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00028] in <4061e52126604f67b6d455853ab7baf7>:0 
  at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <b81453133ee74092816142afbffb5d49>:0 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Omnisharp server is not running Windows 10 - Stack Overflow
Goto VSCODE -> File -> Preferences -> Settings · Type "omnisharp" in the search toolbox · Disable the "Omnisharp: Auto Start" checkbox ·...
Read more >
HELP! VSCode Intellisense stopped working (Again!...)
I've tried to install an older OmniSharp version of VSCode,... nothing... What is really weird is that I don't have any "Failed to...
Read more >
C# – Open VSX Registry
Open VSX is an Eclipse open-source project and alternative to the Visual Studio Marketplace. It is deployed by the Eclipse Foundation at open-vsx.org....
Read more >
Fix Intellisense on VS Code (Omnisharp) for Mac - YouTube
This may also work on Windows/ Linux with similar configurations. I have seen lots of reports of fixes for Windows, in my experience...
Read more >
OmniSharp - .NET and IntelliSense on any platform with your ...
OmniSharp is a family of Open Source projects, each with one goal - To enable great .NET development in YOUR editor of choice....
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