Kestrelhttpserver: Exception after upgrading from rc2 to 1.0

Created on 28 Jun 2016  路  13Comments  路  Source: aspnet/KestrelHttpServer

Ubuntu 15.04 + mono 4.2.3.4 + asp.net core rtm. Any ideas how to fix it?

docker[16814]: Unhandled Exception: docker[16814]: System.TypeInitializationException: The type initializer for 'Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.Constants' threw an exception. ---> System.DllNotFoundException: System.Native docker[16814]: at (wrapper managed-to-native) Interop+Sys:GetUnixNamePrivate () docker[16814]: at Interop+Sys.GetUnixName () <0x417f5790 + 0x0000b> in <filename unknown>:0 docker[16814]: at System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform (OSPlatform osPlatform) <0x417f5720 + 0x00023> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.Constants.GetECONNRESET () <0x417f5350 + 0x0001f> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.Constants..cctor () <0x417f5300 + 0x0000b> in <filename unknown>:0 docker[16814]: --- End of inner exception stack trace --- docker[16814]: at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start () <0x417f4460 + 0x000f8> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run (IWebHost host, CancellationToken token, System.String shutdownMessage) <0x417f4070 + 0x0005d> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run (IWebHost host) <0x417f3c40 + 0x001c7> in <filename unknown>:0 docker[16814]: at Must.Backend.Program.Main (System.String[] args) <0x41623e00 + 0x000d7> in <filename unknown>:0 docker[16814]: [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.Constants' threw an exception. ---> System.DllNotFoundException: S docker[16814]: at (wrapper managed-to-native) Interop+Sys:GetUnixNamePrivate () docker[16814]: at Interop+Sys.GetUnixName () <0x417f5790 + 0x0000b> in <filename unknown>:0 docker[16814]: at System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform (OSPlatform osPlatform) <0x417f5720 + 0x00023> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.Constants.GetECONNRESET () <0x417f5350 + 0x0001f> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.Constants..cctor () <0x417f5300 + 0x0000b> in <filename unknown>:0 docker[16814]: --- End of inner exception stack trace --- docker[16814]: at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start () <0x417f4460 + 0x000f8> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run (IWebHost host, CancellationToken token, System.String shutdownMessage) <0x417f4070 + 0x0005d> in <filename unknown>:0 docker[16814]: at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run (IWebHost host) <0x417f3c40 + 0x001c7> in <filename unknown>:0 docker[16814]: at Must.Backend.Program.Main (System.String[] args) <0x41623e00 + 0x000d7> in <filename unknown>:0

Most helpful comment

@tugberkugurlu

You could probably justln -s /usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Native.so /usr/lib/libSystem.Native.so and be done with it.

All 13 comments

I have the same problem..
Mac osx el capitan + mono 4.40 + asp.net core rtm.

project.json

       {
    "version": "2.0.0",
    "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "debugType": "portable"
   },
   "configurations": {
   "Debug": {
  "buildOptions": {
    "define": [
      "DEBUG"
    ]
  }
},
"Release": {
  "buildOptions": {
    "define": [
      "RELEASE"
    ],
    "optimize": true
  }
}
},
 "dependencies": {
"Microsoft.NETCore.Platforms": "1.0.1",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Configuration.Binder": "1.0.0",
"Serilog.Sinks.RollingFile": "2.0.0-rc-706",
"Ngonzalez.MongoRepository": "2.0.1",
"Ngonzalez.Util": "2.0.1",
"Serilog.Extensions.Logging": "1.0.0"
 },
 "frameworks": {
  "net451": {}
 },
 "runtimeOptions": {
  "configProperties": {
  "System.GC.Server": true,
  "System.GC.Concurrent": true
  }
 }
}

dotnet cli

$ dotnet --info
.NET Command Line Tools (1.0.0-preview2-003121)

Product Information:
Version:            1.0.0-preview2-003121
Commit SHA-1 hash:  1e9d529bc5

 Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.11
 OS Platform: Darwin
 RID:         osx.10.11-x64

Mono is not officially supported. And there is currently a bug that causes any uses of System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(...) to crash on mono.

See https://github.com/dotnet/corefx/issues/9012

I had the same issue after updating to RTM. Running this on Mac with Mono 4.4 when I publish my sample app dotnet publish -c Release -f net451 -o output and go to the output folder and run mono app.exe I get the same error as above.

So I went to /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0 and copied System.Native.dylib to my output folder beside the exe file. When I run it again I still hit the same issue which was weird cause that's how Kestrel loads libuv as far as I know. So I looked at debug output for Mono and for some reason it tried to load libSystem.Native.dylib So I just renamed System.Native.dylib to libSystem.Native.dylib and I was able to run the sample app on Mono on Mac.

I actually have no idea why the last step was happening or if the sample app will even work beyond basic serving hello world. But at least it's not crashing on startup.

I can confirm that copying manually System.Native.so as libSystem.Native.so in the publish folder makes thungs work on linux also.
Big thanks for that find @yousifh

Closing this since Mono is not supported and a workaround exists for people hitting this issue.

@cesarbs Why Mono is not supported every time. It basically works. It just needs a small amount of love.

As far as I can see, the only real groundbreaking stuff you can with the new dotnet stuff is run it on linux. Specifically, docker. Since any real application will be needing to use the net4* platform (which mono provides on linux), this stance of not supported ktnxbye is not good enough.

ASP.Net Core basically works on linux/mono/net451 it just needs a little bit of love from M$. Please!

Mono is not officially supported.

That is amazing! I am in a world where most of the libraries are not available on .NET Core and I cannot progress working on docker because of this :disappointed:

I am having the same issue BTW https://github.com/aspnet/Home/issues/1652

Workaround https://github.com/aspnet/KestrelHttpServer/issues/942#issuecomment-229129202 that has been suggested by @yousifh works, with a few tweaks:

  • I navigated to /usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0 and copied System.Native.so file (not System.Native.dylib, it does't exists for me figured that it's a Mac thing, in Linux it's .so as said on https://github.com/aspnet/KestrelHttpServer/issues/942#issuecomment-230719336) and have put it under my app (~apps/myapp/bin/Debug/net451/ubuntu.14.04-x64).
  • renamed it to libSystem.Native.so analogously.

This is such a shame though if this is the only problem, makes it really hard to transition for people considering lots of OSS libraries not available on coreclr.

@tugberkugurlu

You could probably justln -s /usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Native.so /usr/lib/libSystem.Native.so and be done with it.

We don't test or support mono officially, it's a best effort thing (and community driven at this point). This specific issue is being tracked and discussed here https://github.com/dotnet/corefx/issues/9012

For this problem on OSX, see my comment over on https://github.com/aspnet/KestrelHttpServer/issues/963#issuecomment-236603728.

Bottom line: set DYLD_LIBRARY_PATH to dir of System.Native.dylib and MONO_ENV_OPTIONS='--arch=64'.

@pompomJuice that trick worked on Linux quite well but on Mac, it's not taking effect:

ln -s /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Native.dylib /usr/local/lib/libSystem.Native.dylib

Apparently you cannot write into /usr/lib/ on Mac that easily anymore, hence /usr/local/lib/.

Was this page helpful?
0 / 5 - 0 ratings