Missing Gtk namespace in Monodevelop

Section: Linux

Monodevelop is a quickly maturing application for writing applications for the .Net framework and Mono. While it isn't up to the complexity of Visual Studio or the user friendlyness of Eclipse it is the best tool I've found in Linux for C# development. Unfortunately there seem to be a couple of things that aren't as clear as they could be with some of the requirements.

The problem

Having wiped my Fedora install to get a clean base for Fedora 8 (while keeping my data intact, because Linux is useful for that) I started trying to work on WarFoundry again. After the original System.Windows.Forms version wouldn't open and compile properly using v0.14 that comes with Fedora 8 I quickly installed v0.17 from the Development (future Fedora 9) repositories, along with newer Mono builds.

Everything seemed fine and the code windows would open, so I left it until I had time to actually work on it. While I could modify and compile the library without problems, the GTK# GUI I had started earlier wouldn't compile. The error message was as follows.

The type or namespace name `Gtk' could not be found. Are you missing a using directive or an assembly reference?(CS0246)

Given that gtk-sharp was listed in the references, it was confusing as to why it wouldn't work.

The first diagnosis and fix

The first thing I noticed in the references was that Monodevelop was trying to use the GTK# v2.4.0 assemblies, but that I had 2.10.0 installed. This meant that they were listed at the bottom of the "Edit references" window but not in the packages list at the top.

The first (hackish) solution to the problem was to include references to the actual DLL files and remove the references to the packages. This worked and the application would compile, but it also copied the DLLs to the output folder - not the best solution.

The second diagnosis - has it fixed itself?

After having added gtk- and gdk-sharp from the /usr/lib/mono/gac folder and restarting Monodevelop a couple of times I noticed that they were now listed twice in the bottom of the "Edit references" window, once as an assembly and once as a package.

If you get this behaviour then do not be fooled! I thought Monodevelop had finally realised that these libraries were in the GAC, but no such luck. Removing the assemblies and leaving the packages restored me to the "type or namespace not found" error.

The real solution - devel packages

It turns out the solution is simple, and comparatively logical. The issue is that in /usr/lib/pkgconfig there are a number of .pc files that Monodevelop uses to determine what packages are available. A normal install of Mono/Monodevelop includes some of these files, but not the GTK# ones and it doesn't warn you that you need them.

All that is needed is to install the gtk-sharp-devel RPM to match your gtk-sharp package and Monodevelop will include all of the GTK# related packages in its package list. If you're lucky then it may even correctly select the gtk-sharp and gdk-sharp packages for you!

Having installed the "-devel" package then everything compiled without any need for references direct to assemblies and without any additional DLLs in the output folder. Unfortunately it wasn't until after much searching that the very last post of this thread gave me the answer.

Once again, while Linux is great for easily installing new software from a repository and tinkering with the operating system, it could do with a bit more explanation in some areas. After you've got it working then everything is great.

Navigation