[Gtk-sharp-list] Need help solving a problem using glade-lib/gtk/etc... app on Windows .Net.

Anset anset@anset.org
Wed, 25 Aug 2004 14:56:58 +0200


Hi,

Sorry if this email is a bit long, but I wanted to be complete...

I have written a small program to test gtk-sharp compatibility between linux
(gentoo) and windows (xp). On the windows side I did not install mono. I
want to test compatibility between linux/mono and windows/.net.

To get gtk functionality on the windows pc, I installed the "Gtk# Win32
Installer for Microsoft .NET Framework 1.1 SDK", which I found at
http://forge.novell.com/modules/xfmod/project/?gtks-inst4win.

I used glade-2 to create a gui XML file. The gui is very simple: a text
label and a few buttons.

On linux I used monodevelop to compile the program, embedding the xml file
as a resource. Everything works the way it should. No problems.

Now I copy the exe file over to my windows box and try to run it.

I get an unhandled exception. (see below)

I then compile the program using csc on the windows box. Compilation goes
without a problem, but when I run the program, I get the same unhandled
exception (see below).

I copied the exe I compiled on the windows box with csc over to my linux pc
and there it runs perfectly.

Here is the stack trace I get on the windows box. Again, the stack trace is
identical for both the mcs and csc compiled exe's:

Unhandled Exception: System.ArgumentNullException: Key cannot be null.
Parameter name: key
   at System.Collections.Hashtable.ContainsKey(Object key)
   at GLib.ObjectManager.GetValidParentType(IntPtr raw)
   at GLib.ObjectManager.CreateObject(IntPtr raw)
   at GLib.Object.GetObject(IntPtr o, Boolean owned_ref)
   at GLib.Object.GetObject(IntPtr o)
   at Glade.XML.GetWidget(String name)
   at Glade.XML.BindFields(Object target, Type type)
   at Glade.XML.Autoconnect(Object handler)
   at gtk_hello_world..ctor(String[] args)
   at gtk_hello_world.Main(String[] args)

I have done some digging and came to the following procedure in the
gtk-sharp/glib/ObjectManager.cs file
(from cvs.hispalinux.es):

static Type GetValidParentType (IntPtr raw)
{
   int type_id = gtksharp_get_type_id (raw);
   string typename;
   string mangled;
   Type t;
   // We will always end up at GObject and will break this loop
   while (true) {
         type_id = gtksharp_get_parent_type (type_id);
         typename = Marshal.PtrToStringAnsi (gtksharp_get_type_name_for_id
(type_id));
         if (types.ContainsKey (typename))
            mangled = (string)types[typename];
         else
            mangled = GetExpected (typename);
         t = Type.GetType (mangled);
         if (t != null) {
            return t;
         }
   }
}

The first "if" statement makes the call to ContainsKey which (as far as I
was able to deduce) causes the unhandled exception.

Now the argument that is "null" is "typename". This variable gets its value
with the call just above that line:

typename = Marshal.PtrToStringAnsi (gtksharp_get_type_name_for_id
(type_id));

I was not able to find details about the gtksharp_get_type_name_for_id
function. (or more precisely the g_type_name function that is called by it).
:(

What puzzles me here is that Marshal.PtrToStringAnsi apparantly returns
"null"... Reading the description in the documentation,
Marshal.PtrToStringAnsi will trow an exception if its argument is null, so
whatever gtksharp_get_type_name_for_id (type_id) is returning, it is not
"null". From what I have found on the net, Marshal.PtrToStringAnsi should
not return "null"...

So what happened inside Marshal.PtrToStringAnsi?
And only on the windows .net platform?

This is where I am stuck.

I cannot imagine that gtk-sharp on windows is this broken. So I must be
doing something wrong.
But I'm unable to figure this out...

If anyone can help, I would greatly appreciate it.

All the files I used can be found at http://anset.org/gtk-problem
I put a readme file with info on what file does what (just in case).

Best regards and thank you for your time,

Anset.