Tuesday, 16 July 2019

Running .NET Core apps on Raspberry Pi Zero

Recently I wrote a small app that I was planning to run on my Raspberry Pi Zero, since it's incredibly compact! With .NET Core now being cross platform, I thought it was a simple affair, so I compiled and deployed the app, targeting the linux_arm runtime, and tried to run it on the device, only to be met with this:

Segmentation fault

I thought something was wrong, so I tried it on a newer Raspberry Pi, and everything worked great.

A quick search later and I learned that the Raspberry Pi Zero uses an armv6 processor, while .NET Core JIT depends on armv7 instructions.

I thought that this was the end of it, but upon doing a little more research, I found that the Mono framework can actually run on Raspberry Pi Zero!

The solution was simple: re-compile the app in Framework Dependent - Portable mode, and copy it onto the device. Instead of having a native library, you end up with your app's dll file.

Then on the Raspberry Pi Zero install mono, and run your app!

sudo apt update
sudo apt upgrade
sudo apt install mono-complete
mono ./ConsoleApp.dll
Hello World!

Success! I hope this helps someone else that ran into the same issue