C# with Mono

I’ve been wanting to learn C#. It seems everything is done in C# these days. But I have a Mac. I thought that the only way to program with C# would be on Windows XP via WMWare, but after a bit of research I found I was mistaken.

Enter Mono. (Mono, as in the prefix meaning “one,” not as in the disease.) Mono is an open source, cross platform implementation of the .Net Framework. It is available on a large number of platforms, including Mac OS X, Windows and Linux. Sounds cool, eh? That’s what I thought anyway. So I was excited to download and try it. It even comes with it’s own little IDE, MonoDevelop.

After I installed Mono and MonoDevelop, I was able to compile a quick “Hello World” console application. That was fun and easy. I wondered if I would be able to do the same with a Windows.Forms application. This is where I ran into some complications.

Whenever I tried to use System.Windows.Forms, I would get the following error:

The type or namespace name ‘Windows’ does not exist in the namespace ‘System’. Are you missing an assembly reference?

I searched all around to see what this could possibly mean. The Mono Project website said they supported Windows.Forms on Mac OS X. I had the full version of Mono. I reinstalled Mono and MonoDevelop several times. Unfortunately, since Mono is so new and there isn’t much of a Mac community for it, I was lost.

Finally, I stumbled on the Edit References window in MonoDevelop and found what I was missing. To find it:

  1. In the Project menu, select Edit References.
  2. On the Packages tab, scroll down to and select the assembly you wish to include (mine was System.Windows.Forms).
  3. Click OK.

And that’s all there is to it. My “Hello Form” project compiled just fine. It is important to note, that in order for the Edit References option to be available in the Project menu, you need to be working in an active project, or solution. When I was first trying to compile my “Hello Form” program, I had opened it as a single file and that was a mistake.

It might be best to note here also that System is another available assembly in the list. If you ever get a “missing assembly reference” error, check that list!

The code for my “Hello Form” program was very simple:

using System;
using System.Windows.Forms;

namespace HelloForm
{
    public class HelloForm : Form
    {
        public static void Main()
        {
            Application.Run(new HelloForm());
        }
    }
}
Advertisement

BIOS Update

I’ve been working on a project to turn an old computer into a file server for backup purposes. The plan is to eventually run a script from my laptop which will start the server up and backup all my pictures, movies, music, etc. to the server. One of the hiccups I have run into is trying to figure out if my old Compaq Presario 7PL295 supports wake-on-lan.

Apparently, wake-on-lan is a BIOS setting, but what with my BIOS being so old, I didn’t find the option anywhere. So I went to the HP Customer Care website to see if they had any updates available. I found 3 updates, or ROMPaq’s as they call them. One of them (sp18768, released 2001-11-30) mentioned something about “Added support to show F12 Network boot message” which led me to believe that wake-on-lan was an option. After a bit a blundering, which I’ll go into at greater detail, I eventually installed the ROMPaq, unfortunately without any desired results. The “F12 network boot message” didn’t exist.

I’ve never performed a ROM firmware update before, so I have no idea whether the updates should be applied cumulatively in order. So that’s what I’ll try next, but allow me to document the steps I took to install my first firmware update. First let me explain a little of the situation.

My laptop is a MacBook Pro and therefore has no disk drive. The only way these ROMPaqs work is through a floppy disk. I’ve installed Ubuntu Linux on my Compaq and I don’t have any floppy diskettes anymore. I haven’t used one for years! So the question was, how to run a Windows executable to write to a non-existent floppy disk to update my Compaq’s BIOS?

On my Mac, I opened terminal and entered the following command:

dd bs=512 count=2880 if=/dev/zero of=floppy.img

This creates a image for a blank, unformatted floppy disk. From here I cheated and used VMWare to load Windows XP. I mapped the floppy image in VMWare, formatted the disk and then ran the SoftPaq executable. It placed the ROMPaq on the disk. Magic! But the problem at this point was how to get my virtual disk to load on my non-virtual computer.

I figured there had to be some way to burn the image to CD. After a bit of googling, I found a great article by Mark Alexander, I believe, which details how to do just that.

Using his instructions, I performed the following:

1.) I mounted the floppy image:

hdid floppy.img

2.) I created a temporary folder and copied the contents of the floppy disk to it:

mkdir tmp
cp -Rp /Volumes/<volume name>/* tmp/
cp -p floppy.img tmp/

3.) I created an ISO image using mkisofs. (Since I have a  Mac, I had to install mkisofs through Fink in order to get this one to work.)

mkisofs -pad -b floppy.img -R -o cd.iso tmp

4.) I burned the new ISO to a CD with Disk Utility.

5.) I placed the newly burned floppy disk qua CD into the tray and installed the firmware update.

This actually took me several attempts with several CD’s being burnt up in the process. But I finally got the process down pat. Now I just have to see what happens when I install the rest of the updates.

By the way, I would recommend using CD-RW’s as the medium and leaving the ISO’s on your computer (they’re only a couple megabytes). Especially if you’re applying multiple ROM updates like I am. That way you don’t have to burn up so many CD’s.