ASP.NET Core project targeting .NET 4.5.1 running on Raspberry Pi
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…
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.
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 4.6.1.5/ef43c15 Wed Oct 12 09:29:26 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
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=1.0.0.0, 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
git clone https://github.com/Tragetaschen/libSystem.Native
cd libSystem.Native/src
cc -c -o libSystem.Native.o GetUnixName.c -fpic
cc -shared libSystem.Native.o -o libSystem.Native.so
sudo /usr/bin/install -c -m 644 libSystem.Native.so /usr/local/lib
echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/local.conf
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.
I'll be glad once the official releases are available. 😉