ASP.NET Core project targeting .NET 4.5.1 running on Raspberry Pi

 October 14, 2016

I have been coding a personal project for the past couple weeks. It is a little too soon to unveil, but will say it involves lights, sounds, door switches, and motion sensors. Part of my testing involves running on the intended hardware–Raspberry Pi. However, coding the project in .NET Core left me with a couple stumbling blocks…

1.) No ARM binaries

The first block is the unavailability of binaries for ARM chipsets (although they are projected to arrive next year). Not a show-stopper. I was able to target .NET 4.5.1 with a few minor tweaks.

2.) Getting Mono on the Pi to run the new stuff

NOTE: all coding was done on my main machine, along with building/publishing, and then copied to the Pi.

First thing I did was make sure the Pi has the latest Mono-version:

pi@raspberrypi ~ $ sudo apt-get install --only-upgrade mono-complete

pi@raspberrypi ~ $ mono --version
Mono JIT compiler version 4.6.1 (Stable Wed Oct 12 09:29:26 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors.
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

My first attempt at getting the Windows-build of the project crashed pretty quick:

pi@raspberrypi ~/Documents/projects/net451 $ mono ./app.exe

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly or one of its dependencies.
File name: 'Microsoft.AspNetCore.Hosting.Abstractions, Version=, Culture=neutral, PublicKeyToken=adb9793829ddae60'

And, going into the win7-x64 directory:

pi@raspberrypi ~/Documents/projects/net451/win7-x64 $ mono ./app.exe

Unhandled Exception:
System.AggregateException: One or more errors occurred. ---> System.DllNotFoundException: WS2_32.dll

So, I took a stab at adding a runtime-configuration in project.json:

"runtimes": {
    "debian.8-x64": {}

And then publishing (again, from my main computer, not on the Pi):

dotnet publish -r "debian.8-x64" -c Debug

Got a little further this time, but still a no-go:

Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: System.Native

Thankfully, others in the community have come across this and provided a workaround:

Ref. this comment on GitHub

git clone
cd libSystem.Native/src
cc -c -o libSystem.Native.o GetUnixName.c -fpic
cc -shared libSystem.Native.o -o
sudo /usr/bin/install -c -m 644 /usr/local/lib
echo "/usr/local/lib" | sudo tee /etc/ 
sudo ldconfig -v

Now, my app starts as-expected: 🎉

pi@raspberrypi ~/Documents/projects/net451/debian.8-x64 $ mono ./app.exe

Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

How I now feel


I'll be glad once the official releases are available. 😉