dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.72k stars 1.07k forks source link

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/bin/Debug/netcoreapp1.0'. #560

Closed dazhao-msft closed 7 years ago

dazhao-msft commented 7 years ago

Environment:

  1. VS 15.0.0-RC.2+26027.0.d15prerel
  2. Docker for Windows
  3. Share drive that contains %userprofile%, which is usually c: drive, in the settings of Docker for Windows.

Repro Steps:

  1. Create a new ASP.NET Core Web Application (.NET Core) project.
  2. Uncheck 'Enable Container (Docker) Support' if it is checked in the dialog.
  3. Edit .csproj file to add the following in order to workaround https://github.com/dotnet/sdk/issues/557:
    <PropertyGroup>
    <OutputType>exe</OutputType>
    </PropertyGroup>
  4. Reload project.
  5. Right click on the project, Add, Docker Project Support.
  6. F5.

Expected: VS launches the app to run in a Linux container.

Actual: A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/bin/Debug/netcoreapp1.0'. The program '' has exited with code 131 (0x83).

dazhao-msft commented 7 years ago

Here is more info after turning COREHOST_TRACE on in the Linux container:


You may only use the Microsoft .NET Core Debugger (clrdbg) with Visual Studio Code, Visual Studio or Visual Studio for Mac software to help you develop and test your applications.

Tracing enabled --- Invoked dotnet [version: 1.0.1, commit hash: cee57bf6c981237d80aa1631cfe83cb9ba329f12] main = { /usr/bin/dotnet --additionalprobingpath /root/.nuget/packages bin/Debug/netcoreapp1.0/WebApplication6.dll } Reading fx resolver directory=[/usr/share/dotnet/host/fxr] Considering fxr version=[.]... Considering fxr version=[1.0.1]... Considering fxr version=[..]... Detected latest fxr version=[/usr/share/dotnet/host/fxr/1.0.1]... Resolved fxr [/usr/share/dotnet/host/fxr/1.0.1/libhostfxr.so]... Tracing enabled --- Invoked hostfxr [commit hash: cee57bf6c981237d80aa1631cfe83cb9ba329f12] main Own DLL path=[/usr/share/dotnet/dotnet.dll] Checking if CoreCLR path exists=[/usr/share/dotnet/libcoreclr.so] --- Executing in muxer mode... Parsed known arg --additionalprobingpath = /root/.nuget/packages Detected a non-standalone application, expecting app.dll to execute. Treating application '/app/bin/Debug/netcoreapp1.0/WebApplication6.dll' as a managed executable. App runtimeconfig.json from [/app/bin/Debug/netcoreapp1.0/WebApplication6.dll] Runtime config is cfg=/app/bin/Debug/netcoreapp1.0/WebApplication6.runtimeconfig.json dev=/app/bin/Debug/netcoreapp1.0/WebApplication6.runtimeconfig.dev.json Attempting to read runtime config: /app/bin/Debug/netcoreapp1.0/WebApplication6.runtimeconfig.json Attempting to read dev runtime config: /app/bin/Debug/netcoreapp1.0/WebApplication6.runtimeconfig.dev.json Runtime config [/app/bin/Debug/netcoreapp1.0/WebApplication6.runtimeconfig.json] is valid=[1] realpath(): Invalid argument Executing as a standalone app as per config file [/app/bin/Debug/netcoreapp1.0/WebApplication6.runtimeconfig.json] --- Resolving libhostpolicy.so version from deps json [/app/bin/Debug/netcoreapp1.0/WebApplication6.deps.json] Resolved version from dependency manifest file [/app/bin/Debug/netcoreapp1.0/WebApplication6.deps.json] Dependency manifest /app/bin/Debug/netcoreapp1.0/WebApplication6.deps.json does not contain an entry for runtime.debian.8-x64.Microsoft.NETCore.DotNetHostPolicy The expected libhostpolicy.so directory is [/app/bin/Debug/netcoreapp1.0] The libhostpolicy.so was not found in [/app/bin/Debug/netcoreapp1.0] A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/bin/Debug/netcoreapp1.0'. The program '' has exited with code 131 (0x83).

nguerrera commented 7 years ago

The root cause here was a missing reference to Microsoft.NETCore.App package. The SDK needs this reference to emit a correct runtimeconfig. It should be fixed by https://github.com/aspnet/Templates/pull/774

The workaround if that fix hasn't arrived to you is to add the following to the csproj

    <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
jvieyra92 commented 7 years ago

I'm getting a similar error, and I do have the package reference in my csproj.

Could not find required library libhostpolicy.so in 1 probing paths: /root/.nuget/packages A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/bin/Debug/netcoreapp1.1'. The program '' has exited with code 131 (0x83).

<PackageReference Include="Microsoft.NETCore.App">
      <Version>1.1.0</Version>
</PackageReference>

Are there any other things that would cause this error?

vorotech commented 7 years ago

Have the same error as @jvieyra92. Issue dissappears after second launch of the application with Docker profile selected.

JoseFMP commented 7 years ago

This issue still happening. Even I install explictely the package Microsoft.NETCore.App, the issue still there.

hellfirehd commented 7 years ago

For me as well.



Product Information:
 Version:            1.0.4
 Commit SHA-1 hash:  af1e6684fd

Runtime Environment:
 OS Name:     centos
 OS Version:  7
 OS Platform: Linux
 RID:         centos.7-x64
 Base Path:   /opt/dotnet/sdk/1.0.4

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/usr/app/pdsicp/webapi'.```
nguerrera commented 7 years ago

That error can trigger in different cases. Things have also changed since then to male that packagereference implicit for most projects. Please open new bugs with your repro steps.

FFLSH commented 7 years ago

For me the fix for this was that the directory containing the dll also needs to contain the appropriate runtimeconfig.json and deps.json. I was publishing one project and trying to run other projects which it referenced via their dlls, but the external projects did not have the json files. Published each project to its' own directory.

JoseFMP commented 7 years ago

@nguerrera still happening. .NET Core 2.0 same result. @FFLSH tried with that but no difference. Terrible bug in my opinion. @dazhao-msft @dougkwilson did you guys find any workarounds for this issue?

nguerrera commented 7 years ago

Again, please open a new bug with repro steps. The error message may be the same but the root cause is not.

mattiasw2 commented 6 years ago

I got the same error with dotnet core 2.1.3 on Ubuntu 16.04. I solved it by not only copying the .dll files, but all the other files in the bin folder. Under Windows, the dll-file was enough.

xltarget.deps.json
xltarget.dll
xltarget.pdb
xltarget.runtimeconfig.dev.json
xltarget.runtimeconfig.json
nguerrera commented 6 years ago

@mattiasw2 It is normal that the json files are required. Furthermore, when copying to another machine, you should use dotnet publish and copy the publish directory to the target machine. The app in the standard bin/ directory is for development/debugging. See https://docs.microsoft.com/en-us/dotnet/core/deploying/

mattiasw2 commented 6 years ago

Ok, understood, but they are more or less empty, and no ref to the library 'libhostpolicy.so'. So, since I doesn't seem to be the first, maybe the simplest solution is to add more information for the error message, like "You most likely forgot to publish the json files."

JoseFMP commented 6 years ago

Yes, this issue for me still not solved.

nguerrera commented 6 years ago

Third time: Please open a new issue and include the full steps you are using to reproduce the problem. This issue was about a very specific problem that is no longer relevant. The error message can be triggered by different means.