Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnisharp stopped working #5160

Closed
marcospgp opened this issue Apr 9, 2022 · 3 comments
Closed

Omnisharp stopped working #5160

marcospgp opened this issue Apr 9, 2022 · 3 comments

Comments

@marcospgp
Copy link

marcospgp commented Apr 9, 2022

Issue Description

I'm using VSCode with Unity. Everything had been working properly for a long time, but today getting back to the project Omnisharp is not starting correctly. I believe a recent update to VSCode, Unity's VSCode package, or Omnisharp itself may be the culprit.

I have tried downgrading Unity's VSCode package, doing a clean install of VSCode (including deleting .vscode folder), and a clean install of Mono, to no avail.

I am grateful for any help in figuring this out!

Steps to Reproduce

Open VSCode

Expected Behavior

Omnisharp starts

Actual Behavior

Omnisharp no starts

Logs

OmniSharp log

Starting OmniSharp server at 4/9/2022, 8:16:20 PM
    Target: /Users/marcos-casual/Documents/GitHub/dead-drive/dead-drive.sln

OmniSharp server started with Mono 6.12.0.
    Path: /Users/marcos-casual/.vscode/extensions/ms-dotnettools.csharp-1.24.3-darwin-x64/.omnisharp/1.38.2/omnisharp/OmniSharp.exe
    PID: 761

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 12.1 (x64)
[info]: OmniSharp.Services.DotNetCliService
        Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
        Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 16.6.0 - "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin"
            2: StandAlone 17.1.1 - "/Users/marcos-casual/.vscode/extensions/ms-dotnettools.csharp-1.24.3-darwin-x64/.omnisharp/1.38.2/omnisharp/.msbuild/Current/Bin"
[warn]: OmniSharp.CompositionHostBuilder
        It looks like you have Mono installed which contains a MSBuild lower than 16.8.0 which is the minimum supported by the configured .NET Core Sdk.
 Try updating Mono to the latest stable or preview version to enable better .NET Core Sdk support.
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 16.6.0 - "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin"
            CscToolExe = csc.exe
            CscToolPath = /Users/marcos-casual/.vscode/extensions/ms-dotnettools.csharp-1.24.3-darwin-x64/.omnisharp/1.38.2/omnisharp/.msbuild/Current/Bin/Roslyn
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 <36514b14425c4337b446653c547aa9c3>:0 
  at System.RuntimeType.GetPropertyCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Type[] types, System.Boolean allowPrefixLookup) [0x00010] in <36514b14425c4337b446653c547aa9c3>:0 
  at System.RuntimeType.GetProperties (System.Reflection.BindingFlags bindingAttr) [0x00000] in <36514b14425c4337b446653c547aa9c3>:0 
  at System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties (System.Type type) [0x00014] in <36514b14425c4337b446653c547aa9c3>: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.IEnumerable`1[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.IEnumerable`1[T] assemblies) [0x00031] in <f78fde32b7b244ca95ad9f75f5377ae7>:0 
  at OmniSharp.HostServicesAggregator.CreateHostServices () [0x00000] in <3997e19046634a39a20d03c6385fc69b>:0 
  at OmniSharp.OmniSharpWorkspace..ctor (OmniSharp.HostServicesAggregator aggregator, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, OmniSharp.FileWatching.IFileSystemWatcher fileSystemWatcher) [0x00046] in <3997e19046634a39a20d03c6385fc69b>: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 <b65fb505403e4a9f95ed53beadc952de>: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 <b65fb505403e4a9f95ed53beadc952de>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_1.<Main>b__1 () [0x0017d] in <529aa935fa644d439a555153e68c17a3>:0 
  at OmniSharp.CommandLineApplication+<>c__DisplayClass12_0.<OnExecute>b__0 () [0x0000b] in <2c738f48401c42ab8866fe9742b40aa0>: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 <2c738f48401c42ab8866fe9742b40aa0>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00028] in <529aa935fa644d439a555153e68c17a3>:0 
  at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <2c738f48401c42ab8866fe9742b40aa0>: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.66.1
C# Extension: 1.24.3

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

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

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

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

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.3 [/usr/local/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
@filipw
Copy link
Contributor

filipw commented Apr 10, 2022

This error is coming from Roslynator which is en external component you must have installed, not part of this extension, which looks like is broken here.

Find the file ~/.omnisharp/omnisharp.json and remove all references to Roslynator from there.

@marcospgp
Copy link
Author

marcospgp commented Apr 10, 2022

@filipw Thanks for addressing this! I have not found a .omnisharp.json file in the .omnisharp folder though - the folder appears to be empty 😢

Edit: Oh, is this the configuration file for omnisharp? I have one in the project root which looks like this:

{
    "RoslynExtensionsOptions": {
        "EnableAnalyzersSupport": true,
        "LocationPaths": [
            "./nuget-manually-downloaded-packages/microsoft.codeanalysis.netanalyzers.6.0.0/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/microsoft.unity.analyzers.1.12.0/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/roslynator.analyzers.3.2.0/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/roslynator.formatting.analyzers.1.2.1/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/stylecop.analyzers.1.1.118/analyzers/dotnet/cs"
        ]
    }
}

Removing all of the entries in LocationPaths fixed the issue, but I do want to keep using these analyzers 😕
Was there an update to how Omnisharp handles Roslynator analyzers?

Edit 2: I confirmed that the issue only occurs when any of the two Roslynator entries are present:

"./nuget-manually-downloaded-packages/roslynator.analyzers.3.2.0/analyzers/dotnet/cs",
"./nuget-manually-downloaded-packages/roslynator.formatting.analyzers.1.2.1/analyzers/dotnet/cs",

I tried updating them to the latest version, resulting in this new .omnisharp.json file:

{
    "RoslynExtensionsOptions": {
        "EnableAnalyzersSupport": true,
        "LocationPaths": [
            "./nuget-manually-downloaded-packages/microsoft.codeanalysis.netanalyzers.6.0.0/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/microsoft.unity.analyzers.1.12.0/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/roslynator.analyzers.4.1.0/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/roslynator.formatting.analyzers.4.1.0/analyzers/dotnet/cs",
            "./nuget-manually-downloaded-packages/stylecop.analyzers.1.1.118/analyzers/dotnet/cs"
        ]
    }
}

But the issue still occurs:

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.

Edit 3: This seems to be the same issue as #5147. I have use global mono set to always and use modern net set to false.

The final answer on that issue does not seem correct:

I believe the Roslynator extension manipulates omnisharp.json on install to inject its assemblies into the OminSharp extensions to be loaded, and even when you remove Roslynator, the file would stay modified. But yeah this is external dependency issue in this case.

If this were a Roslynator issue, it wouldn't show up for me as I am using a fixed version of the analyzers, which I only now updated manually. The analyzers worked before and did not change, so this means something else must have changed - likely Omnisharp, unless it could be a Unity VSCode package change?

Edit 4: Managed to trace the issue down to the update of VSCode's C# extension from 1.24.1 to 1.24.2. Rolling back to 1.24.1 fixes the issue, while updating to 1.24.2 reintroduces it. This update is where Omnisharp was updated from 1.38.1 to 1.38.2.

@JoeRobich
Copy link
Member

A lot has changed with O# code analysis since this issue was opened. If you are still having problems, please open a new issue at https://github.com/omnisharp/omnisharp-roslyn/issues

@JoeRobich JoeRobich closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants