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


Attachment: button.glade
Description: application/glade

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");
                }
        }
}
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 ();
	}
}

Reply via email to