question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DllNotFoundException: System.Native when executing RuntimeInformation.IsOSPlatform on mono

See original GitHub issue

I’m trying to run a basic ASP.NET Core application on Ubuntu 16.04 using mono 4.2.1 and .Net Core 1.0:

  1. mkdir webapp, cd webapp, dotnet new -t web
  2. in project.json, remove Microsoft.NETCore.App from dependencies, change frameworks to: "net451": { }, remove prepublish from scripts
  3. dotnet restore, dotnet publish
  4. 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:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
CL0SeYcommented, Aug 8, 2016

@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.

ln -s /usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Native.so /usr/lib/libSystem.Native.so
0reactions
aggiebencommented, Aug 26, 2016

@jasoncavett see dotnet/cli#3964 . You might be able to make use of the same install_name_tool workaround described there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DllNotFoundException: System.Native when executing ...
I'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,...
Read more >
DllNotFoundException
Any failure seems to result in a DllNotFoundException which only indicates that the original native library being loaded was not found.
Read more >
Determine Operating System in .NET Core
Method. System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(). Possible Argument. OSPlatform.Windows OSPlatform.OSX OSPlatform.
Read more >
Unknown Tmodloader Error (System.DllNotFoundException
Go to Steam and right-click Terraria and click 'Properties'; Click 'Local Files' tab and then click 'Browse Local Files'; Click and run ' ......
Read more >
Loading Native Libraries in C# | Rendered Obsolete
Platform returns "Unix" for Unix or OSX, so use RuntimeInformation here var isOsx = System.Runtime.InteropServices.RuntimeInformation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found