DllNotFoundException: System.Native when executing RuntimeInformation.IsOSPlatform on mono
See original GitHub issueI’m trying to run a basic ASP.NET Core application on Ubuntu 16.04 using mono 4.2.1 and .Net Core 1.0:
mkdir webapp
,cd webapp
,dotnet new -t web
- in project.json, remove Microsoft.NETCore.App from dependencies, change frameworks to:
"net451": { }
, remove prepublish from scripts dotnet restore
,dotnet publish
mono bin/Debug/net451/ubuntu.16.04-x64/publish/webapp.exe
At the last step, I get an exception:
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: System.Native
at (wrapper managed-to-native) Interop+Sys:GetUnixNamePrivate ()
at Interop+Sys.GetUnixName () <0x40d02200 + 0x0000b> in <filename unknown>:0
at System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform (OSPlatform osPlatform) <0x40d02190 + 0x00023> in <filename unknown>:0
at Microsoft.Extensions.Logging.Console.ConsoleLogger..ctor (System.String name, System.Func`3 filter, Boolean includeScopes) <0x40d01bb0 + 0x00153> in <filename unknown>:0
[snip]
Since there is no System.Native in the publish
directory, I attempt to work around this by adding "runtime.ubuntu.16.04-x64.runtime.native.System": "1.0.1"
to dependencies.
This copies System.Native.so
(and System.Native.a
) to publish
, but I still get the same exception. Then, by setting MONO_LOG_LEVEL="debug"
, I figure out that mono is mostly looking for libSystem.Native
(or libSystem.Native.so
). So I run mv System.Native.so libSystem.Native
and now the application finally executes.
Trivial console application trying to reproduce the issue behaves differently. dotnet publish
publishes a different version of System.Runtime.InteropServices.RuntimeInformation.dll: it seems it’s the one from runtimes/unix/lib/netstandard1.1 from the NuGet package for the ASP.NET Core application, and the one from lib/net45 for the trivial console application. I believe this is caused by referencing the libuv package, which forces the use of runtimes.
Note: I didn’t use dotnet run
at first, because that encounters a a different bug. But the workaround for that (use dotnet run -c Release
) throws the same DllNotFoundException
as above.
Originally reported as https://github.com/dotnet/core/issues/205.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
@jasoncavett I’ve worked around it by putting this into my Dockerfile for mono builds but that would probably have side-effects if you’re looking to target future versions of the framework. Not sure if it works on OSX either, but could give it a go.
@jasoncavett see dotnet/cli#3964 . You might be able to make use of the same
install_name_tool
workaround described there.