Why .net program on linux under mono fails to run?

757 Views Asked by At

I ran my Delphi-prism (.NET) program on Linux under Mono. It ran for awhile and crashed with the following error message on the terminal. But the same program runs perfectly fine on Windows 7

Can anyone tell me why?

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at System.Windows.Forms.XEventQueue+PaintQueue.Dequeue () [0x00000] in <filename unknown>:0
  at System.Windows.Forms.XplatUIX11.GetMessage (System.Object queue_id, System.Windows.Forms.MSG& msg, IntPtr handle, Int32 wFilterMin, Int32 wFilterMax) [0x00000] in <filename unknown>:0
  at System.Windows.Forms.XplatUI.GetMessage (System.Object queue_id, System.Windows.Forms.MSG& msg, IntPtr hWnd, Int32 wFilterMin, Int32 wFilterMax) [0x00000] in <filename unknown>:0
  at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in <filename unknown>:0
  at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext context) [0x00000] in <filename unknown>:0
  at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm) [0x00000] in <filename unknown>:0
  at Millennia.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
2

There are 2 best solutions below

6
kristianp On

It looks like your program is using Windows Forms. Support for Windows Forms is not the best in mono. Mono provides the runtime and libraries, but if you want to make a cross-platform program you need to consider the UI libraries you make use of as well.

Update (2016):

My original answer is probably wrong. According to this page, support for Windows Forms 2.0 is complete, but there may still be a number of bugs, I haven't tried it. However if you use a third-party UI library, for example Infragistics, they probably won't work due to native calls.

Have a look at this page for more info on porting Winforms apps, including the tool MoMA that can help.

0
kpe On

I had the same problem (.net, Linux, Mono). My program has a provider-subsrciber pattern. The provider is on another thread. The main form is subscribed to the provider. When it is fired:

    private void RefreshLabels(ParameterMap pm)
    {
        string StateValueKey = string.Empty;
        string svkValue = string.Empty;

        if (InvokeRequired)
        {
            BeginInvoke(new RefreshItemsDelegate(RefreshLabels), new object[] { pm });
        }
        else
        {

..... it comes across from the other thread and does its job.

Another subscriber fired an event on the main form also. I ignored this event and the problem DISAPPEARED.