Raspberry PI: So I wanted to program in C#, Mono is the way on Linux

Now falling on from my setup I decided I wanted to code in C#. This is my personal preference as I did not want to learn Python, C or C++. I find C# to be far more elegant and Visual Studio is a dream.

Anyway, I connected to my PI with Putty and installed Mono by executing the following command ‘sudo apt-get install mono-runtime’. I chose only to install the runtime since all development would be done on the Windows 7 laptop.

Once the PI had downloaded and installed the package I was ready to go..

I chose to create a .NET 2.0 console application. My thoughts where that this would be the most compatible on Mono, not known exactly how much of the .NET framework was implemented.

My test code, which I compiled and ran is below. (Oh, I uploaded the exe via FTP using the same address and port 22 as SSH). FYI Linux is case sensitive.

using System;
using System.Collections.Generic;
using System.Text;

namespace TESTAPP
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, I am PI");
Console.ReadKey();
}
}
}

And the result was this..

 

 

 

Notice that I can’t execute the program because I don’t have permission. This is normal on Linux, by default nothing is allowed to run unless its given permission.
This can be done by executing the command ‘sudo chmod 755 TESTAPP.exe’ or from your FTP client changing the permission to 755, which allows execution.

Let rerun and see what happens..

Nope.. Still not happening.

So now we have an error telling us that an assembly is missing. After some Google’ing I decided to install the complete package by executing ‘sudo apt-get install mono-complete’.

Now doing this took forever and you get a whole host of lines starting with ‘Problem:’. But that aside, I continued and ran the TESTAPP once again…

 

 

Bam.. it worked. That’s it, looks like we have our .NET up and running on Linux. Next up I attach and setup my IO extender and start to try things out.