Search code examples
c#linuxwinformsmonowine

System.NullReferenceException in Linux Mono using Fast Colored Text Box


I am creating a small GUI in WinForms and am currently working on implementing a syntax highlighter. I found a library that runs great in windows and provides a dll for usage. However, the library seems to always crash in Linux. Here is the error I'm getting:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at FastColoredTextBoxNS.FastColoredTextBox..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FastColoredTextBoxNS.FastColoredTextBox:.ctor ()
  at FDE.FGUI..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FDE.FGUI:.ctor ()
  at FDE.FGUI.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at FastColoredTextBoxNS.FastColoredTextBox..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FastColoredTextBoxNS.FastColoredTextBox:.ctor ()
  at FDE.FGUI..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FDE.FGUI:.ctor ()
  at FDE.FGUI.Main () [0x00000] in <filename unknown>:0 

From the error message, it seems that Mono isn't seeing the dll given the <filename unknown> error during the constructor. Admittedly, The library I'm using (FastColoredTextBox) does not pass MoMA as it has a fair amount of P/Invokes. However, some people seemed to say they were able to get it running by avoiding the conflicting methods.

Here's the clincher, though. I decided to try to run the GUI through WINE and completely bypass Mono. Since it ran fine it Windows, I thought this would fix the error. However, the exact same error message pops up in Wine. I even have a shared folder between Windows and my Ubuntu live machine. The same exact executable will run on perfect Windows, but crash with this error in Linux. At this point, after hours of researching, I'm stumped.

Is there a certain way a dll has to be loaded in Mono or does the error lie in Mono/Wine incompatibilities with WinForms?


Solution

  • I looked at the source to the library. Assuming I've found the right library, it's calling the Win32 API, which isn't going to work on stock Mono.

    Running under Wine should work better, but Wine is only partially implementing the Win32 API.

    You may need to find a cross-platform replacement.