razzmatazz / csharp-language-server

Roslyn-based LSP language server for C#
MIT License
574 stars 37 forks source link

Can't find .NET Core MSBuild when using ASDF #82

Open hochata opened 1 year ago

hochata commented 1 year ago

When trying to run it, the server starts but then crashes because it can't find any SDK. I installed the dotnet SDK using ASDF with the dotnet plugin, so there is probably a misconfiguration. Both DOTNET_ROOT and MSBuildSDKsPath are set.

This error is probably not directly related the csharp-ls, as I get the same error with Omnisharp, but I don't really know where else to ask for help.

This is the last message from the server.

[jsonrpc] Server exited with status 9
error in process filter: eglot--error: [eglot] -32603: System.InvalidOperationException: Failed to find an appropriate version of .NET Core MSBuild. Call to hostfxr_resolve_sdk2 failed. There may be more details in stderr.
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetDotNetBasePaths(String workingDirectory)+MoveNext()
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory)+MoveNext()
   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.IsEmpty[T](IEnumerable`1 source) in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 851
   at CSharpLanguageServer.Server.handleInitialize@178-5.Invoke(Unit _arg8) in /home/runner/work/csharp-language-server/csharp-language-server/src/CSharpLanguageServer/Server.fs:line 180
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 528
   at Ionide.LanguageServerProtocol.Server.sendServerNotification@111-3.Invoke(AsyncActivation`1 ctxt) in /_//src/LanguageServerProtocol.fs:line 111
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
error in process filter: [eglot] -32603: System.InvalidOperationException: Failed to find an appropriate version of .NET Core MSBuild. Call to hostfxr_resolve_sdk2 failed. There may be more details in stderr.
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetDotNetBasePaths(String workingDirectory)+MoveNext()
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory)+MoveNext()
   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.IsEmpty[T](IEnumerable`1 source) in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 851
   at CSharpLanguageServer.Server.handleInitialize@178-5.Invoke(Unit _arg8) in /home/runner/work/csharp-language-server/csharp-language-server/src/CSharpLanguageServer/Server.fs:line 180
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 528
   at Ionide.LanguageServerProtocol.Server.sendServerNotification@111-3.Invoke(AsyncActivation`1 ctxt) in /_//src/LanguageServerProtocol.fs:line 111
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112

This is the content of stderr

[stderr] No .NET SDKs were found.
[stderr] 
[stderr] Download a .NET SDK:
[stderr] https://aka.ms/dotnet/download
[stderr] 
[stderr] Learn about SDK resolution:
[stderr] https://aka.ms/dotnet/sdk-not-found
[server-reply] (id:1) ERROR Mon Apr 10 19:45:28 2023:
(:jsonrpc "2.0" :id 1 :error
      (:code -32603 :message "System.InvalidOperationException: Failed to find an appropriate version of .NET Core MSBuild. Call to hostfxr_resolve_sdk2 failed. There may be more details in stderr.\n   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetDotNetBasePaths(String workingDirectory)+MoveNext()\n   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory)+MoveNext()\n   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext()\n   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\n   at Microsoft.FSharp.Collections.SeqModule.IsEmpty[T](IEnumerable`1 source) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\seq.fs:line 851\n   at CSharpLanguageServer.Server.handleInitialize@178-5.Invoke(Unit _arg8) in /home/runner/work/csharp-language-server/csharp-language-server/src/CSharpLanguageServer/Server.fs:line 180\n   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 528\n   at Ionide.LanguageServerProtocol.Server.sendServerNotification@111-3.Invoke(AsyncActivation`1 ctxt) in /_//src/LanguageServerProtocol.fs:line 111\n   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 112"))

This is the result of dotnet --info

.NET SDK:
 Version:   7.0.202
 Commit:    6c74320bc3

Runtime Environment:
 OS Name:     void
 OS Version:  
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/hochata/.asdf/installs/dotnet/7.0.202/sdk/7.0.202/

Host:
  Version:      7.0.4
  Architecture: x64
  Commit:       0a396acafe

.NET SDKs installed:
  7.0.202 [/home/hochata/.asdf/installs/dotnet/7.0.202/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.4 [/home/hochata/.asdf/installs/dotnet/7.0.202/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.4 [/home/hochata/.asdf/installs/dotnet/7.0.202/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/home/hochata/.asdf/installs/dotnet/7.0.202]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Any idea about what I could do to solve it?

hochata commented 1 year ago

Ok, I figured it out. It seem that to find the SDK, the MSBuildLocator follows the dotnet symlink until it arrives to the real binary. But the dotnet executable in my path was just a shim created by ASDF.

Because the final executable was not the real SDK, the search failed. I solved by setting adding the real dotnet to the path.

Is there a Wiki or something where I can document this? It was pretty cryptic error.

Or maybe I should ping the mantainer for the ASDF plugin... I'm not sure.

If someone thinks this shouldn't be mentioned here, I'll just close the issue.

llimllib commented 1 year ago

@hochata many thanks for the solution

wojciech-kulik commented 7 months ago

@hochata thank you! I wouldn't figure it out in a million years! In my case it helped to unlink/uninstall dotnet from brew and just install it manually, so that my only path (where dotnet) is /usr/local/share/dotnet/dotnet

My error was:

Error executing vim.schedule lua callback: ...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1308: RPC[Error] code_name = InternalError, message = "System.InvalidOperationException: Failed to find a
n appropriate version of .NET Core MSBuild. Call to hostfxr_resolve_sdk2 failed. There may be more details in stderr.\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetDotNetBasePaths(String workingDirectory)+MoveNext()\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory)+MoveNext()\
   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext()\
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\
   at Microsoft.FSharp.Collections.SeqModule.IsEmpty[T](IEnumerable`1 source) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\seq.fs:line 851\
   at CSharpLanguageServer.Server.handleInitialize@196-6.Invoke(Unit _arg9) in /home/runner/work/csharp-language-server/csharp-language-server/src/CSharpLanguageServer/Server.fs:line 198\
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 528\
   at Ionide.LanguageServerProtocol.Server.sendServerNotification@111-3.Invoke(AsyncActivation`1 ctxt) in /_//src/LanguageServerProtocol.fs:line 111\
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 112"
stack traceback:
        [C]: in function 'assert'
        ...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1308: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
areiass36 commented 5 months ago

I was able to fix the problem by uninstalling asdf with homebrew, deleting all of its plugin files manually and installing again; It was quite painful, but it worked.