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 can't find libhostfxr.so #166543

Closed
felschr opened this issue Mar 31, 2022 · 11 comments · Fixed by #170296
Closed

omnisharp can't find libhostfxr.so #166543

felschr opened this issue Mar 31, 2022 · 11 comments · Fixed by #170296
Labels
0.kind: bug Something is broken

Comments

@felschr
Copy link
Member

felschr commented Mar 31, 2022

Describe the bug

omnisharp complains that it can't findlibhostfxr.so.

omnisharp
A fatal error occurred. The required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/nix/store/05kjphpaj0wbiss2xpip4nlpwrps7r3q-omnisharp-roslyn-1.38.1/src/].
If this is a framework-dependent application, install the runtime in the global location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet].

The .NET runtime can be found at:
  - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=nixos-x64&apphost_version=6.0.3echo $DOTNET_ROOT
/nix/store/awy23dg72sxnwy5x2jw67axm9xfibkfz-dotnet-core-combined

Steps To Reproduce

Install omnisharp-roslyn & try to start it.

Expected behavior

omnisharp should work without throwing an error, at least when DOTNET_ROOT is set.

Notify maintainers

@tesq0 @ericdallo @corngood

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
  /nix/store/5c9ixzdc3yr5yknb9axn2adagpi13m1n-bash-interactive-5.1-p16-dev
copying path '/nix/store/5c9ixzdc3yr5yknb9axn2adagpi13m1n-bash-interactive-5.1-p16-dev' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 5.17.0, NixOS, 22.05 (Quokka), 22.05.20220330.710fed5`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.0pre20220322_d5d4d98`
 - nixpkgs: `/nix/store/g1562lf0ibiwj5d2ahz2prxy6dsxim7r-source`
@felschr felschr added the 0.kind: bug Something is broken label Mar 31, 2022
@felschr
Copy link
Member Author

felschr commented Apr 1, 2022

I found the cause for this issue on my machine. I was using pkgs.dotnetCorePackages.combinePackages. When I change it to use use only one SDK, omnisharp will work again:

- dotnet-combined = with pkgs.dotnetCorePackages;
-   combinePackages [ sdk_6_0 ];
+ dotnet-combined = pkgs.dotnetCorePackages.sdk_6_0;

This works for my use-case since I only have one SDK installed at the moment. It's not optimal, though and it was working previously at some point.

@felschr
Copy link
Member Author

felschr commented Apr 1, 2022

Also, if I unset DOTNET_ROOT, omnisharp is still working.
So I guess it should be possible to fix this in:

makeWrapper $out/src/OmniSharp $out/bin/omnisharp \
--prefix DOTNET_ROOT : ${dotnet-sdk} \
--suffix PATH : ${dotnet-sdk}/bin

@felschr
Copy link
Member Author

felschr commented Apr 1, 2022

I get another error now, though:

{"Event":"MsBuildProjectDiagnostics","Body":{"FileName":"/home/felschr/Project/Project.csproj","Warnings":[],"Errors":[{"LogLevel":"Error","FileName":"/nix/store/m9m9g151nhkvljxhb04f102y7a5a87wz
-dotnet-sdk-6.0.201/sdk/6.0.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets","Text":"The \"ProcessFrameworkReferences\" task failed unexpectedly.\nSystem.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.1.0.1
03, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)\nFile name: 'NuGet.Frameworks, Version=6.1.0.103, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\n ---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.F
rameworks, Version=6.1.0.103, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.\n   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)\n   at System.Runtime.Loader.AssemblyLoad
Context.LoadFromAssemblyPath(String assemblyPath)\n   at Microsoft.Build.Shared.MSBuildLoadContext.Load(AssemblyName assemblyName)\n   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)\n   at System.Runtime.Loader.AssemblyLoadContext.Resolve(Int
Ptr gchManagedAssemblyLoadContext, AssemblyName assemblyName)\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.ExecuteCore()\n   at Microsof
t.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, T
askHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)","StartLine":90,"StartColumn":5,"EndLine":0,"EndColumn":0}]},"Seq":27,"Type":"event"}

Possibly related:
OmniSharp/omnisharp-roslyn#2305
#164276

@mdarocha
Copy link
Contributor

mdarocha commented Apr 3, 2022

I get another error now, though:

{"Event":"MsBuildProjectDiagnostics","Body":{"FileName":"/home/felschr/Project/Project.csproj","Warnings":[],"Errors":[{"LogLevel":"Error","FileName":"/nix/store/m9m9g151nhkvljxhb04f102y7a5a87wz
-dotnet-sdk-6.0.201/sdk/6.0.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets","Text":"The \"ProcessFrameworkReferences\" task failed unexpectedly.\nSystem.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.1.0.1
03, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)\nFile name: 'NuGet.Frameworks, Version=6.1.0.103, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\n ---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.F
rameworks, Version=6.1.0.103, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.\n   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)\n   at System.Runtime.Loader.AssemblyLoad
Context.LoadFromAssemblyPath(String assemblyPath)\n   at Microsoft.Build.Shared.MSBuildLoadContext.Load(AssemblyName assemblyName)\n   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)\n   at System.Runtime.Loader.AssemblyLoadContext.Resolve(Int
Ptr gchManagedAssemblyLoadContext, AssemblyName assemblyName)\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.ExecuteCore()\n   at Microsof
t.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, T
askHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)","StartLine":90,"StartColumn":5,"EndLine":0,"EndColumn":0}]},"Seq":27,"Type":"event"}

Possibly related: OmniSharp/omnisharp-roslyn#2305 #164276

I got the same error. Is it caused by a version incompatibility? The latest version of the omnisharp-roslyn package in nixpkgs-unstable is 1.38.1, and the latest version of dotnet-sdk is 6.0.201.

v1.38.2 of omnisharp-roslyn - https://github.com/OmniSharp/omnisharp-roslyn/releases/tag/v1.38.2 - mentions updating build tools to match dotnet 6.0.201. Does updating omnisharp or downgrading dotnet help this issue?

@Infinidoge
Copy link
Contributor

Omnisharp has been updated to v1.38.2 (on master, at least), does this error still occur?

@mdarocha
Copy link
Contributor

mdarocha commented Apr 17, 2022

Omnisharp has been updated to v1.38.2 (on master, at least), does this error still occur?

Still occurs for me. Now the error is that it cannot find System.Configuration.ConfigurationManager with version 4.0.3

It seems there is a mismatch, dotnet-sdk package contains System.Configuration.ConfigurationManager with version 4.0.0:

$ strings /nix/store/2r9ikyxvnbf76scc7ymcipwkijmmdbhd-dotnet-sdk-6.0.201/sdk/6.0.201/System.Configuration.ConfigurationManager.dll | grep System.Configuration,        
WSystem.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

The same error was reported in omnisharp repository - OmniSharp/omnisharp-roslyn#2383

@Infinidoge
Copy link
Contributor

Infinidoge commented Apr 17, 2022

I've been seeing that same error thrown on my end as well.

Went ahead and bumped the dotnet core packages, and that doesn't seem to change the result (tested sdk 6.0.202):

$ strings /nix/store/nm4zfzbx0c48vbg4sr4qx92fpqx4ysmi-dotnet-sdk-6.0.202/sdk/6.0.202/System.Configuration.ConfigurationManager.dll | grep System.Configuration,
WSystem.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Interestingly, sdk 7.0.100-preview.3.22179.4 also showed 4.0.0.0:

$ strings /nix/store/zad8f78611z3c2znmsqrsavbc4xjbs2m-dotnet-sdk-7.0.100-preview.3.22179.4/sdk/7.0.100-preview.3.22179.4/System.Configuration.ConfigurationManager.dll | grep System.Configuration,
WSystem.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

(Will be PRing the updates, and addition of 7.0, momentarily)
EDIT: Won't be PRing the updates yet, breaks a number of packages currently. Will PR the addition of 7.0 though

@Infinidoge
Copy link
Contributor

Possibly related:
OmniSharp/omnisharp-roslyn#2359

@mdarocha
Copy link
Contributor

I've been seeing that same error thrown on my end as well.

Went ahead and bumped the dotnet core packages, and that doesn't seem to change the result (tested sdk 6.0.202):

$ strings /nix/store/nm4zfzbx0c48vbg4sr4qx92fpqx4ysmi-dotnet-sdk-6.0.202/sdk/6.0.202/System.Configuration.ConfigurationManager.dll | grep System.Configuration,
WSystem.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Interestingly, sdk 7.0.100-preview.3.22179.4 also showed 4.0.0.0:

$ strings /nix/store/zad8f78611z3c2znmsqrsavbc4xjbs2m-dotnet-sdk-7.0.100-preview.3.22179.4/sdk/7.0.100-preview.3.22179.4/System.Configuration.ConfigurationManager.dll | grep System.Configuration,
WSystem.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

(Will be PRing the updates, and addition of 7.0, momentarily)
EDIT: Won't be PRing the updates yet, breaks a number of packages currently. Will PR the addition of 7.0 though

Seems like the omnisharp-roslyn package incorretly refernces this dll. It seems like a problem with the upstream repo, not the nix packaging.

Btw, I made a PR with the dotnet 6 bump here: #168486

@GGG-KILLER
Copy link
Contributor

GGG-KILLER commented Apr 22, 2022

Still getting this error, anyone has a solution for it?

File name: 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
 ---> System.IO.FileLoadException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>g__TryLoadAssembly|3(AssemblyName assemblyName)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>b__2(AssemblyLoadContext _, AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.Build.Evaluation.ToolsetReader.ReadAllToolsets(Dictionary`2 toolsets, ToolsetConfigurationReader configurationReader, PropertyDictionary`1 environmentProperties, PropertyDictionary`1 globalProperties, ToolsetDefinitionLocations locations)
   at Microsoft.Build.Evaluation.ProjectCollection.InitializeToolsetCollection(ToolsetConfigurationReader configReader)
   at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, IEnumerable`1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents, Boolean loadProjectsReadOnly)
   at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, ToolsetDefinitionLocations toolsetDefinitionLocations)
   at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore(String filePath, IReadOnlyDictionary`2 projectConfigurationsInSolution, IList`1 loggers) in /build/source/src/OmniSharp.MSBuild/ProjectLoader.cs:line 152
   at OmniSharp.MSBuild.ProjectLoader.BuildProject(String filePath, IReadOnlyDictionary`2 configurationsInSolution) in /build/source/src/OmniSharp.MSBuild/ProjectLoader.cs:line 84
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load(String filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader, Guid sessionId, DotNetInfo dotNetInfo) in /build/source/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs:line 117
   at OmniSharp.MSBuild.ProjectManager.<>c__DisplayClass32_0.<LoadProject>b__0() in /build/source/src/OmniSharp.MSBuild/ProjectManager.cs:line 305
   at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject(String projectFilePath, Func`1 loader) in /build/source/src/OmniSharp.MSBuild/ProjectManager.cs:line 316

UPDATE: Downgrading this single package to stable temporarily fixed it.

@mdarocha
Copy link
Contributor

After some investigation, the issue with System.Config.ConfigurationManager in upstream repo was fixed by OmniSharp/omnisharp-roslyn#2359

This was fixed by removing the problematic dll during build, causing omnisharp-roslyn to find the dll in dotnet sdk folder, and bind properly. But since it was added to the build.cake file, which nix build doesn't use, the fix did not carry over to nixpkgs.

The simple solution is to add a manual removal of dlls to the installPhase, mimicking the hack upstream. This causes omnisharp to work again on my machine:

  omnisharp-roslyn = super.omnisharp-roslyn.overrideAttrs (old: rec {
    installPhase = ''
      mkdir -p $out/bin
      cp -r bin/Release/OmniSharp.Stdio.Driver/net6.0 $out/src

      # Delete files to mimick hacks in https://github.com/OmniSharp/omnisharp-roslyn/blob/bdc14ca/build.cake#L594
      rm $out/src/NuGet.*.dll
      rm $out/src/System.Configuration.ConfigurationManager.dll

      makeWrapper $out/src/OmniSharp $out/bin/omnisharp \
        --prefix DOTNET_ROOT : ${super.dotnet-sdk} \
        --suffix PATH : ${super.dotnet-sdk}/bin
    '';
  });

I'm going to try adding the above fix in a PR to nixpkgs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants