[Gtk-sharp-list] System.InvalidCastException from generated
code
Martin Willemoes Hansen
mwh@sysrq.dk
Mon, 26 Jan 2004 14:05:08 +0100
On Mon, 2004-01-26 at 03:25, Ben Maurer wrote:
> Hello,
>
> While I was playing around with gtksourceview today, i found that
> placing a mark in the text would create an error. The error that was
> thrown was:
>
> > Unhandled Exception: System.InvalidCastException: Cannot cast from source type to destination type
> > in <0x00085> Gtk.SourceBuffer:CreateMarker (string,string,Gtk.TextIter)
Yes, I have seen that error too, just in some other area (DiaCanvas# and
also gtksourceview#).
> Looking into the code, i found that the generator made the code:
>
>
> > public Gtk.SourceMarker CreateMarker(string name, string type, Gtk.TextIter where) {
> > IntPtr raw_ret = gtk_source_buffer_create_marker(Handle, name, type, ref where);
> > Gtk.SourceMarker ret = (Gtk.SourceMarker) GLib.Object.GetObject(raw_ret);
> > return ret;
> > }
try changing the code to be like this:
Gtk.SourceMarker ret = new Gtk.SourceMarker (raw_ret);
>
> I placed a Console.WriteLine in there to see the type of the object that
> was coming out of the cache. It was a TextIter.
>
> I think the problem comes from the folowing C code:
>
>
> > 33 GType
> > 34 gtk_source_marker_get_type (void)
> > 35 {
> > 36 static GType our_type = 0;
> > 37
> > 38 /* this function's solely purpose is to allow us to later
> > 39 * derive GtkSourceMarker from other base object and not break
> > 40 * ABI compatibility (since this way the type is resolved at
> > 41 * runtime) */
> > 42 if (!our_type) {
> > 43 our_type = GTK_TYPE_TEXT_MARK;
>
> It seems that Gtk# is confused as to the type of the object. What would
> be the best way to fix this?
Yes, I would like to know that as well :o)
Until it is fixed, you can correct the error by hiding the function and
creating a working function with a .custom file.
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
--
Martin Willemoes Hansen
--------------------------------------------------------
E-Mail mwh@sysrq.dk Website mwh.sysrq.dk
IRC MWH, freenode.net
--------------------------------------------------------