mono/mono — pull request #898 by UCIS (2014-02-11 22:45:33+00:00)
Title: Prevent exception in finalization of Form class

If initialization of the Form class or one of its base classes fails, possibly because X11 is not available and the constructor of the parent Control class throws an exception, the owned_forms member is not initialized. This results in a NullReferenceException during initialization, if the error that occurs during construction is handled.

Stack traces:
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.WindowsFormsSynchronizationContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in :0
at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in :0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in :0
at System.Windows.Forms.XplatUI..cctor () [0x00000] in :0
--- End of inner exception stack trace ---
at System.Windows.Forms.Theme.get_MenuAccessKeysUnderlined () [0x00000] in :0
at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in :0
at System.Windows.Forms.Control..ctor () [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in :0
--- End of inner exception stack trace ---
at System.Windows.Forms.Control..ctor () [0x00000] in :0
at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in :0
at System.Windows.Forms.ContainerControl..ctor () [0x00000] in :0
at System.Windows.Forms.Form..ctor () [0x00000] in :0
at AutoCRCheck.frmOptions..ctor () [0x00000] in :0
at (wrapper remoting-invoke-with-check) AutoCRCheck.frmOptions:.ctor ()
at AutoCRCheck.Program.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.WindowsFormsSynchronizationContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in :0
at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in :0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in :0
at System.Windows.Forms.XplatUI..cctor () [0x00000] in :0
--- End of inner exception stack trace ---
at System.Windows.Forms.Theme.get_MenuAccessKeysUnderlined () [0x00000] in :0
at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in :0
at System.Windows.Forms.Control..ctor () [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in :0
--- End of inner exception stack trace ---
at System.Windows.Forms.Control..ctor () [0x00000] in :0
at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in :0
at System.Windows.Forms.ContainerControl..ctor () [0x00000] in :0
at System.Windows.Forms.Form..ctor () [0x00000] in :0
at AutoCRCheck.frmOptions..ctor () [0x00000] in :0
at (wrapper remoting-invoke-with-check) AutoCRCheck.frmOptions:.ctor ()
at AutoCRCheck.Program.Main (System.String[] args) [0x00000] in :0

---------------------------------------------------------
Handling the previous exception results in the following exception:

System.NullReferenceException: Object reference not set to an instance of an object
at System.Windows.Forms.Form.Dispose (Boolean disposing) [0x00000] in :0
at AutoCRCheck.frmOptions.Dispose (Boolean disposing) [0x00000] in :0
at System.ComponentModel.Component.Finalize () [0x00000] in :0