Wednesday, April 6, 2011

Broken Mono C# code using System.Windows.Forms

A couple of months back I started a relatively simple C# app which I was compiling with Mono.

I try to resume work on this today, and despite having an executable proving it compiled fine before, it is now complaining about System.Windows.Forms

C:\Program Files\Mono-2.0.1\bin>mcs ../projects/test_1/test.cs
../projects/test_1/test.cs(2,14): error CS0234: The type or namespace name 'Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings

I found a forum post of someone with the same error, and this was recommended:

mcs Program.cs -r:System.Windows.Forms.dll -r:System.Drawing.dll -v2

However, the -v2 argument doesn't work, and without it there are just a series of other namespace errors (ToolStripButton and similar).

I have downloaded the latest Mono 2.2 but this still produces the same error.

How do I fix this?

From stackoverflow
  • gmcs Program.cs -r:System.Windows.Forms.dll -r:System.Drawing.dll
    

    gmcs uses the .NET 2.0 profile.

    JaredPar : curious, what's the g stand for?
    d0k : if I remember correctly it stands for generics
    Peter Boughton : Thanks, this worked. Not sure why I didn't note that this was necessary last time.
    jpobst : generics. Originally the compiler was a fork/branch of mcs to add generics. Eventually, everything from C# 2.0 was put into it. It was later merged back with mcs, but so many people are used to calling gmcs, that the name wasn't dropped.
    Vanuan : "-pkg:dotnet" also works

0 comments:

Post a Comment