jmederosalvarado / roslyn.nvim

Roslyn LSP plugin for neovim
MIT License
203 stars 38 forks source link

Failure to load due to System.IO.FileLoadException when external dependencies are present #18

Open ppebb opened 9 months ago

ppebb commented 9 months ago

Full lsp log output is [ERROR][2023-12-07 22:30:08] ...lsp/handlers.lua:556 "[LanguageServerProjectSystem] Failure while loading /home/ppeb/gitclone/isp2/src/isp2.csproj: The \"ProcessFrameworkReferences\" task failed unexpectedly.\nSystem.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.8.0.32767, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)\nFile name: 'NuGet.Frameworks, Version=6.8.0.32767, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\n ---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.8.0.32767, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyBinder, String ilPath, String niPath, ObjectHandleOnStack retAssembly)\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)\n at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)\n at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)\n at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.<>c.<AddPacksForFrameworkReferences>b__217_0(ITaskItem item)\n at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()\n at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\n at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.AddPacksForFrameworkReferences(List`1 packagesToDownload, List`1 runtimeFrameworks, List`1 targetingPacks, List`1 runtimePacks, List`1 unavailableRuntimePacks, List`1& knownRuntimePacksForTargetFramework)\n at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.ExecuteCore()\n at Microsoft.NET.Build.Tasks.TaskBase.Execute()\n at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\n at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)"

This results in external dependencies being unresolved. I managed to fix this by adding the ~/.local/share/nvim/roslyn directory to my runtime path, but I am unsure if there is a better solution or if anyone else is experiencing this.

lawrence-laz commented 9 months ago

Having the same issue, here's :LspLog:

[ERROR][2023-12-17 16:54:11] ...lsp/handlers.lua:557    "[LanguageServerProjectSystem] Failure while loading /Users/llaz/git/playground/dotnet/console/console.csproj: The \"ProcessFrameworkReferences\" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.8.0.117, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
File name: 'NuGet.Frameworks, Version=6.8.0.117, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
 ---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.8.0.117, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.<>c.<AddPacksForFrameworkReferences>b__193_0(ITaskItem item)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.AddPacksForFrameworkReferences(List`1 packagesToDownload, List`1 runtimeFrameworks, List`1 targetingPacks, List`1 runtimePacks, List`1 unavailableRuntimePacks, List`1& knownRuntimePacksForTargetFramework)
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)"

Workaround of adding ~/.local/share/nvim/roslyn to the PATH seems to help.

EDIT: Nope, it didn't help for me. I mistook treesitter for LSP working, the same error is still visible in the logs and LSP is not giving anything.

ppebb commented 9 months ago

You may need to change out the Nuget.Frameworks.dll in your roslyn folder. You can try finding the a copy of the right version using sudo find / -iname "Nuget.Frameworks.dll" | xargs exiftool > output, and then find one copy dll containing the right version, then copy whatever file you find into your roslyn folder. Not sure why the bundled version is incorrect.

jmederosalvarado commented 9 months ago

What do you mean by external reference? I just tried go to definition with Newtonsoft.Json (added as a nuget package to my project) and it correctly decompiled the source and navigated to a temp file with the code. It would be very helpful if you could provide a minimal example to reproduce the issue.

ppebb commented 9 months ago

To reproduce the issue, I reinstalled roslyn using CSInstallRoslyn, and used dotnet new console to create a new project, dotnet new sln, and dotnet sln add Test.csproj to create a test project. Then even something as simple as a Console.WriteLine does not work and shows using System; as unnecessary and does not resolve correctly (turns out it is not just external dependencies).

Note that this only occurs when the version of Nuget.Frameworks.dll is 6.8.0.112, which is the one that comes bundled when running CSInstallRoslyn. If I swap the dll out for one of version 6.8.0.32767 I found elsewhere then it works just fine.

jmederosalvarado commented 9 months ago

Can you try installing the language server from gh release instead of using CSInstallRoslyn?

Use tar zxf /path/to/roslyn.tar.gz -C ~/.local/share/nvim/roslyn and previously delete the contents of ~/.local/share/nvim/roslyn to install from release package.

ppebb commented 9 months ago

The github release works fine for me. Seems whatever CSInstallRoslyn downloads is outdated or a bugged build.

lawrence-laz commented 6 months ago

Can you try installing the language server from gh release instead of using CSInstallRoslyn?

Use tar zxf /path/to/roslyn.tar.gz -C ~/.local/share/nvim/roslyn and previously delete the contents of ~/.local/share/nvim/roslyn to install from release package.

This helped 👍 Any idea why CSInstallRoslyn acts differently?