[Gtk-sharp-list] Maybe a bug in ListStore under Windows

Michele Beltrame admin at talkblade.info
Sun Jul 3 07:52:40 EDT 2005


I'm trying to iterate trhough a ListStore: under Linux with mono 1.1.8
it works, but on Windows XP with mono 1.1.8 it throws a

I created a test code, here it goes:

---Code BEGIN---
using System;
using Gtk;

public class XNWindow : Gtk.Window {
	private TreeView tv;
	private ListStore ls;

	public XNWindow(string wname): base(wname)
		// Create TreeView
		tv = new TreeView();
		tv.HeadersVisible = true;

		// Define a column
		TreeViewColumn col = new TreeViewColumn();
		CellRenderer colr = new CellRendererText();
		col.Title = "Azienda";
		col.PackStart(colr, true);
		col.AddAttribute(colr, "text", 0);

		// Create and fill the ListStore for the TreeView
		ls = new ListStore(typeof(string));
		tv.Model = ls;
		for (int i = 0; i <= 10; i++) {

		Button b = new Button("Foreach");
		b.Clicked += Foreach_clicked;
		VBox v = new VBox();

	private void Foreach_clicked(object o, EventArgs a)
		ls.Foreach(new TreeModelForeachFunc(MyPrintForeach));

	private bool MyPrintForeach(TreeModel model, TreePath path, TreeIter iter)
		Console.WriteLine ((string)ls.GetValue(iter, 0));

		// We return false so the loop will keep on going
		return false;


class XNMain
	public static void Main (string[] args)
		XNWindow mainw = new XNWindow("ListStore possible bug");
---Code END---

It first fills a ListStore and then tries to print out its elements when
the Foreach button is pressed. This is what I get under Windows:

---Output BEGIN---

Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object
in <0x00000> <unknown method>
in (wrapper managed-to-native) Gtk.ListStore:gtk_tree_model_foreach
in <0x00046> Gtk.ListStore:Foreach (Gtk.TreeModelForeachFunc func)
in <0x00044> XNWindow:Foreach_clicked (System.Object o, System.EventArgs a)
in (wrapper delegate-invoke)
gs (object,System.EventArgs)
in <0x000bb> GtkSharp.voidObjectSignal:voidObjectCallback (IntPtr arg0,
Int32 key)
in (wrapper native-to-managed)
GtkSharp.voidObjectSignal:voidObjectCallback (int
in <0x00000> <unknown method>
in (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00007> Gtk.Application:Run ()
in <0x00038> XNMain:Main (System.String[] args)
---Output END---

It seems to print the first two entires correctly, but then it throws
the exeption. I tried with other ListStore objects with different and
more complex content and I always get this exception when trying to
"Foreach" on them. However, this happens only on Windows.

	Thanks, Michele.

Michele Beltrame
ICQ# 76660101

More information about the Gtk-sharp-list mailing list