[Gtk-sharp-list] Gtk# on Windows: InvalidCastException in GLib.ObjectManager.CreateObject

Sebastian scut@nb.in-berlin.de
Sun, 17 Apr 2005 12:18:58 +0800


This is a multi-part message in MIME format.
--------------000508000505060001020702
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit


Hello everybody,

I am trying to port a small program using glade#/gtk# from Linux to 
Windows, however I experience a crash on Windows 2000 for even simple 
Gtk# programs.

On Linux I use the Debian/unstable libgtk-cil package, version 1.0.4, 
producing the GAC entries:

glade-sharp, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=35e10195dab3c99f
glib-sharp, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=35e10195dab3c99f
gnome-sharp, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=35e10195dab3c99f
gtk-sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f

On Windows I use the Windows Gtk# runtime installer, version 1.9.2.0 from
http://forge.novell.com/modules/xfcontent/private.php/gtks-inst4win/Win32%20Runtime%20Installer/v1.9.2.0/gtksharp-runtime-1.9.2-win32-0.3.exe
and the Microsoft .NET 1.1 runtime.


1. hw is a simple Gtk# program, not using Glade#.  It works on both 
Linux and Windows for me.

mcs /out:hw.exe hw.cs /pkg:gtk-sharp /r:System.Drawing


2. gs is a simple Glade# program using the "button.glade" file.

Compiled with:
mcs /out:gs.exe gs.cs /pkg:gtk-sharp /pkg:glade-sharp

It works on Linux, but produces the following exception under Windows:

Unhandled Exception: System.InvalidCastException: Specified cast is not 
valid.
    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 GladeSamples.GladeTest..ctor(String[] args)
    at GladeSamples.GladeTest.Main(String[] args)


The larger program I want to port produces exactly the same trace and 
also uses Glade#, so its most likely the same error.

Is this a known bug (if so, how can I get around it?), or should I file 
a bugzilla entry?


Thanks,
Sebastian


--------------000508000505060001020702
Content-Type: application/x-glade;
 name="button.glade"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="button.glade"

PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PiA8IS0tKi0gbW9kZTogeG1s
IC0qLS0+CjwhRE9DVFlQRSBnbGFkZS1pbnRlcmZhY2UgU1lTVEVNICJodHRwOi8vZ2xhZGUu
Z25vbWUub3JnL2dsYWRlLTIuMC5kdGQiPgoKPGdsYWRlLWludGVyZmFjZT4KCjx3aWRnZXQg
Y2xhc3M9Ikd0a1dpbmRvdyIgaWQ9IndpbmRvdzEiPgogIDxwcm9wZXJ0eSBuYW1lPSJ2aXNp
YmxlIj5UcnVlPC9wcm9wZXJ0eT4KICA8cHJvcGVydHkgbmFtZT0idGl0bGUiIHRyYW5zbGF0
YWJsZT0ieWVzIj53aW5kb3cxPC9wcm9wZXJ0eT4KICA8cHJvcGVydHkgbmFtZT0idHlwZSI+
R1RLX1dJTkRPV19UT1BMRVZFTDwvcHJvcGVydHk+CiAgPHByb3BlcnR5IG5hbWU9IndpbmRv
d19wb3NpdGlvbiI+R1RLX1dJTl9QT1NfTk9ORTwvcHJvcGVydHk+CiAgPHByb3BlcnR5IG5h
bWU9Im1vZGFsIj5GYWxzZTwvcHJvcGVydHk+CiAgPHByb3BlcnR5IG5hbWU9InJlc2l6YWJs
ZSI+VHJ1ZTwvcHJvcGVydHk+CiAgPHByb3BlcnR5IG5hbWU9ImRlc3Ryb3lfd2l0aF9wYXJl
bnQiPkZhbHNlPC9wcm9wZXJ0eT4KICA8cHJvcGVydHkgbmFtZT0iZGVjb3JhdGVkIj5UcnVl
PC9wcm9wZXJ0eT4KICA8cHJvcGVydHkgbmFtZT0ic2tpcF90YXNrYmFyX2hpbnQiPkZhbHNl
PC9wcm9wZXJ0eT4KICA8cHJvcGVydHkgbmFtZT0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hdGlvbl90aW1lPSJNb24sIDA1IEFwciAyMDA0IDEzOjMxOjU3IEdNVCIvPgog
ICAgPC93aWRnZXQ+CiAgPC9jaGlsZD4KPC93aWRnZXQ+Cgo8L2dsYWRlLWludGVyZmFjZT4K

--------------000508000505060001020702
Content-Type: text/x-csharp;
 name="gs.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="gs.cs"

namespace GladeSamples {
        using System;
        using Gtk;
        using Glade;

        public class GladeTest
        {
                public static void Main (string[] args)
                {
                        new GladeTest(args);
                }
 
                /* The following two lines "import" the Glade objects, allowing
                 * us to work with the signal handlers we created earlier.
                 * If you do not import your objects this way, you must write
                 * your own signal handling code. */

                [Glade.Widget]      
                Button button1;

                public GladeTest (string[] args) 
                {
                        Application.Init();
      
                         /* The next lines load the glade file button.glade
                          * (in the current directory), select window1 and 
                          * connect it to the current object, an instance
                          * of GladeTest. */ 

                        Glade.XML gxml = new Glade.XML ("button.glade", "window1", null);
                        gxml.Autoconnect (this);

                        button1.BorderWidth=10;

                        Application.Run();
                }
                
                  /* The following two methods implement the signal handling code
                   * defined in the UI designer*/

                public void on_window1_delete_event (object o, DeleteEventArgs args) 
                {
                        Application.Quit ();
                        args.RetVal = true;
                }
    
                public void on_button1_clicked (System.Object obj, EventArgs e) 
                {
                        Console.WriteLine ("Button 1 clicked");
                }
        }
}

--------------000508000505060001020702
Content-Type: text/x-csharp;
 name="hw.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="hw.cs"

using Gtk;
using GtkSharp;
using System;
using System.Drawing;

public class HelloWorld {
	/* This is a callback function. The data arguments are ignored
	 * in this example. More on callbacks below. */
	static void hello (object obj, EventArgs args)
	{
		Console.WriteLine("Hello World");
		Application.Quit ();
	}

	static void delete_event (object obj, DeleteEventArgs args)
	{
		/* If you return FALSE in the "delete_event" signal handler,
		 * GTK will emit the "destroy" signal. Returning TRUE means
		 * you don't want the window to be destroyed.
		 * This is useful for popping up 'are you sure you want to quit?'
		 * type dialogs. */

		    Console.WriteLine ("delete event occurred\n");
		    Application.Quit ();
	}

	public static void Main(string[] args)
	{
		/* This is called in all GTK applications. Arguments are parsed
		 * from the command line and are returned to the application. */
		Application.Init ();

		/* create a new window */
		Window window = new Window ("helloworld");
		/* When the window is given the "delete_event" signal (this is given
		 * by the window manager, usually by the "close" option, or on the
		 * titlebar), we ask it to call the delete_event () function
		 * as defined above. The data passed to the callback
		 * function is NULL and is ignored in the callback function. */

		window.DeleteEvent += new DeleteEventHandler (delete_event);
    
		/* Sets the border width of the window. */
		window.BorderWidth = 10;
		/*  gtk_container_set_border_width (GTK_CONTAINER (window), 10);*/
    
		/* Creates a new button with the label "Hello World". */ 
		Button btn = new Button ("Hello World");
    
		/* When the button receives the "clicked" signal, it will call the
		 * function hello() passing it NULL as its argument.  The hello()
		 * function is defined above. */
		btn.Clicked += new EventHandler (hello);

		/* This packs the button into the window (a gtk container). */
		window.Add (btn);

		/* The final step is to display this newly created widget. */
		window.ShowAll ();

		/* All GTK applications must have a gtk_main(). Control ends here
		* and waits for an event to occur (like a key press or
		* mouse event). 
		* In C#, we use Application.Run(), as used in Windows.Forms*/

		Application.Run ();
	}
}

--------------000508000505060001020702--