GTK# in Visual Studio 2010

HOLOGRAPHICpizza picture HOLOGRAPHICpizza · Jul 5, 2012 · Viewed 13.9k times · Source

I've been trying all day to get GTK# working in Visual Studio 2010 on Windows Server 2008 R2 x64 so that I can start writing nice cross-platform GUI applications, but I'm somewhat new to C# and I'm having a world of trouble.

I installed the latest Mono for Windows which includes GTK#. I also installed a Mono 2.10.8 profile to be the target framework of my project loosely following the guide from here: http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/

I created a new Windows Forms application and removed references to the windows forms stuff and adding references for GTK# stuff, loosely following the guide from here: http://jrwren.wrenfam.com/blog/2008/11/01/gtk-in-visual-studio-2008-on-vista-x64/

I also added a reference to gtk-dotnet in addition to the ones from that guide.

This is my application's complete code:

using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using Gtk;

namespace GridToGo
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.Init();
            Window myWin = new Window("My first GTK# Application! ");
            myWin.Resize(200, 200);
            myWin.Destroyed += new EventHandler(myWin_Destroyed);
            Label myLabel = new Label();
            myLabel.Text = "Hello World!!!!";
            myWin.Add(myLabel);
            myWin.ShowAll();
            Application.Run();
        }

        static void myWin_Destroyed(object sender, EventArgs e)
        {
            Application.Quit();
        }
    }
}

When I try to run this with any configuration, I get the following exception:

System.TypeInitializationException was unhandled
  Message=The type initializer for 'Gtk.Application' threw an exception.
  Source=gtk-sharp
  TypeName=Gtk.Application
  StackTrace:
       at Gtk.Application.Init()
       at GridToGo.Program.Main() in F:\visual-studio\GridToGo\GridToGo\Program.cs:line 13
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.DllNotFoundException
       Message=Unable to load DLL 'glibsharpglue-2': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       Source=glib-sharp
       TypeName=""
       StackTrace:
            at GLib.Thread.glibsharp_g_thread_supported()
            at GLib.Thread.get_Supported()
            at Gtk.Application..cctor()
       InnerException: 

I can't figure out how to get it to find that dll! I even tried copying 4 copies of the DLL into pretty much every folder in the solution with the following names: glibsharpglue-2 glibsharpglue-2.dll glibsharpglue-2.o glibsharpglue-2.o.dll! I also even tried installing the GTK all-in-one package from the GTK site and adding its bin folder to my system path, and then copying the same 4 dlls into that folder, all with no luck.

Any advice for my crazy problem? I feel like I'm missing something big here. >_<

Answer

HOLOGRAPHICpizza picture HOLOGRAPHICpizza · Jul 5, 2012

I figured it out! Mono for Windows was completely unnecessary. GTK# for .NET is what I needed. For anyone in the future wanting to set up their Windows environment for cross platform GTK# development, here are the steps I followed:

  1. Install a Mono project target with directions from here: http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/
  2. Install GTK# for .NET from the official Mono download site.
  3. Install Glade/GTK+ for Windows, sourceforge project here: http://sourceforge.net/projects/gladewin32/
  4. Create a new C# project targeting Mono.
  5. Reference the necessary assemblies for your project from where you installed GTK# for .NET.