slluis/xwt — Issue #3: Window.MainMenu = null results in NullReferenceException [GTK backend]
Author: luiscubal
Created: 2011-12-08 22:55:09+00:00
State: open

Description:
Attempting to set the MainMenu of a Window to null results in a NullReferenceException.

System:
Linux Ubuntu x86-64 (11.10, I think)
MonoDevelop 2.6
Mono 2.10.5

Minimalistic example:

```c#
using Xwt;

class MainClass
{
public static void Main (string[] args)
{
Application.Initialize("Xwt.GtkBackend.GtkEngine, Xwt.Gtk, Version=1.0.0.0");

Window w = new Window();
w.MainMenu = null;
w.Show();

Application.Run();
w.Dispose();
}
}
```

Expected behavior:
The behavior should be the same as if the `w.MainMenu = null;` line was commented out.
Additionally, if there already was a menu previously set, I'd expect w.MainMenu to remove it.
If this was by design, ArgumentNullException would be a better exception to throw. However, I think there are legitimate reasons to want to remove the main menu.

Stack Trace:

```
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
at Xwt.GtkBackend.WindowBackend.SetMainMenu (IMenuBackend menu) [0x00023] in /home/luis/Documents/xwt/Xwt.Gtk/Xwt.GtkBackend/WindowBackend.cs:97
at Xwt.Window.set_MainMenu (Xwt.Menu value) [0x00007] in /home/luis/Documents/xwt/Xwt/Xwt/Window.cs:164
at (wrapper remoting-invoke-with-check) Xwt.Window:set_MainMenu (Xwt.Menu)
at MainClass.Main (System.String[] args) [0x00010] in /home/luis/Documents/xwt/QuickTest/Main.cs:10
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at Xwt.GtkBackend.WindowBackend.SetMainMenu (IMenuBackend menu) [0x00023] in /home/luis/Documents/xwt/Xwt.Gtk/Xwt.GtkBackend/WindowBackend.cs:97
at Xwt.Window.set_MainMenu (Xwt.Menu value) [0x00007] in /home/luis/Documents/xwt/Xwt/Xwt/Window.cs:164
at (wrapper remoting-invoke-with-check) Xwt.Window:set_MainMenu (Xwt.Menu)
at MainClass.Main (System.String[] args) [0x00010] in /home/luis/Documents/xwt/QuickTest/Main.cs:10
```