OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.79k stars 420 forks source link

OmniSharp throws MSBuildNotFoundException #2407

Closed jdrst closed 2 years ago

jdrst commented 2 years ago

Hi, i'm trying to run omnisharp (1.39.0) with doom emacs under fedora. Starting the server throws the following error:

The following clients were selected based on priority: (server-id omnisharp, priority -1)
OmniSharp.Services.DotNetCliService: Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK | 
OmniSharp.Services.DotNetCliService: Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK | 
OmniSharp.Services.DotNetCliService: DotNetPath set to /usr/lib64/dotnet/dotnet | 
OmniSharp.Services.DotNetCliService: DotNetPath set to /usr/lib64/dotnet/dotnet | 
OmniSharp.MSBuild.Discovery.MSBuildLocator: Located 0 MSBuild instance(s) | 
OmniSharp.MSBuild.Discovery.MSBuildLocator: Located 0 MSBuild instance(s) | 
OmniSharp.Extensions.JsonRpc.InputHandler: Failed to handle request initialize 1 - OmniSharp.MSBuild.Discovery.MSBuildNotFoundException: Could not locate MSBuild instance to register with OmniSharp.
  at OmniSharp.MSBuild.Discovery.Extensions.RegisterDefaultInstance (OmniSharp.MSBuild.Discovery.IMSBuildLocator msbuildLocator, Microsoft.Extensions.Logging.ILogger logger, OmniSharp.Services.DotNetInfo dotNetInfo) [0x000b1] in <4afa8cba4e6b43e3a16fcca35fdc1d41>:0 
  at OmniSharp.CompositionHostBuilder.Build (System.String workingDirectory) [0x000ad] in <4afa8cba4e6b43e3a16fcca35fdc1d41>:0 
  at OmniSharp.LanguageServerProtocol.LanguageServerHost.CreateCompositionHost (OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer server, OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams initializeParams, OmniSharp.CommandLineApplication application, Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action`1[T] configureLogging) [0x0017d] in <9843221f127b4c1a9250fba4580c89f8>:0 
  at OmniSharp.LanguageServerProtocol.LanguageServerHost.Initialize (OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer server, OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams initializeParams, System.Threading.CancellationToken cancellationToken) [0x00000] in <9843221f127b4c1a9250fba4580c89f8>:0 
  at OmniSharp.Extensions.LanguageServer.Server.LanguageServer+<>c__DisplayClass77_0.<MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InternalInitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle>b__0 (OmniSharp.Extensions.LanguageServer.Protocol.Server.OnLanguageServerInitializeDelegate handler, System.Threading.CancellationToken ct) [0x00012] in <a65ee41ef84f44d8810b866724a97eec>:0 
  at OmniSharp.Extensions.LanguageServer.Protocol.LanguageProtocolEventingHelper+<>c__DisplayClass0_1`2[TDelegate,THandler].<Run>b__2 (System.Threading.CancellationToken ct) [0x00000] in <16970f5ac0364766b872ef4b5abe0a02>:0 
  at System.Reactive.Linq.QueryLanguage.StartAsyncImpl (System.Func`2[T,TResult] actionAsync, System.Reactive.Concurrency.IScheduler scheduler) [0x0000d] in <3a11ea46836344a282870ba916885e3d>:0 
--- End of stack trace from previous location where exception was thrown ---

  at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InternalInitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle (OmniSharp.Extensions.LanguageServer.Protocol.Models.InternalInitializeParams request, System.Threading.CancellationToken token) [0x00133] in <a65ee41ef84f44d8810b866724a97eec>:0 
  at OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x0031e] in <a65ee41ef84f44d8810b866724a97eec>:0 
  at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x00077] in <a65ee41ef84f44d8810b866724a97eec>:0 
  at MediatR.Pipeline.RequestPreProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x0013e] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestPostProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x0007e] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x00084] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x00276] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x00084] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x001e7] in <856ae299ee314304bc3affd17d8d5868>:0 
  at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1[TDescriptor].<RouteRequest>g__InnerRoute|5_0 (Microsoft.Extensions.DependencyInjection.IServiceScopeFactory serviceScopeFactory, OmniSharp.Extensions.JsonRpc.Server.Request request, TDescriptor descriptor, System.Object params, System.Threading.CancellationToken token, Microsoft.Extensions.Logging.ILogger logger) [0x000fc] in <f52078c2a67749cdb3fc490a4675d4eb>:0 
  at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1[TDescriptor].RouteRequest (OmniSharp.Extensions.JsonRpc.IRequestDescriptor`1[TDescriptor] descriptors, OmniSharp.Extensions.JsonRpc.Server.Request request, System.Threading.CancellationToken token) [0x00622] in <f52078c2a67749cdb3fc490a4675d4eb>:0 
  at OmniSharp.Extensions.JsonRpc.InputHandler+<>c__DisplayClass38_0.<RouteRequest>b__5 (System.Threading.CancellationToken ct) [0x000f2] in <f52078c2a67749cdb3fc490a4675d4eb>:0  | Method='initialize' RequestId='1'

both mono and the dotnet 6 sdk are installed:

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.105
 Commit:    1c35735293

Runtime Environment:
 OS Name:     fedora
 OS Version:  36
 OS Platform: Linux
 RID:         fedora.36-x64
 Base Path:   /usr/lib64/dotnet/sdk/6.0.105/

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

.NET SDKs installed:
  6.0.105 [/usr/lib64/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.5 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.5 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
mono --version
Mono JIT compiler version 6.12.0.122 (tarball Thu Jan 20 20:34:53 UTC 2022)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    Interpreter:   yes
    LLVM:          supported, not enabled.
    Suspend:       hybrid
    GC:            sgen (concurrent by default)

running omnisharp from the command line results in the same behaviour.

jdrst commented 2 years ago

this seems to be a problem with emacs lsp-mode default installation for omnisharp using the latest net6.0 build works fine via cli. just to clarify: the correct way to run the net6.0 build is via dotnet runtime (dotnet OmniSharp.dll), right?

filipw commented 2 years ago

the correct way to run the net6.0 build is via dotnet runtime (dotnet OmniSharp.dll), right?

yes correct, it is not a self-contained application, but a framework-dependent one.

jdrst commented 2 years ago

Further investigations:

setting the lsp-mode download url (which defaults to the normal release instead of the net6 one) to the net6 release sadly did not resolve the issue. It seems that lsp-emacs tries to start the run binary, which throws Cannot open assembly './OmniSharp.exe': No such file or directory., which can be confirmed on the cli. Both the OmniSharp binary and dotnet OmniSharp.dll work though. lsp-mode also allows setting a binary path. Setting this to the OmniSharp binary works and resolves my original issue.