[Mono-list] Mono, Windows Forms, and Headless operation

Robert Jordan robertj at gmx.net
Fri Jan 8 16:29:17 UTC 2016

On 07.01.2016 22:24, George, Glover E ERDC-RDE-ITL-MS wrote:
> Hi all,
> We’re currently porting a Windows Forms Application to Mono, and have
> generally had great success.  However, we have now hit a critical
> decision point, and were hoping for some guidance on the best route
> forward.   If we don’t have X11, mono fails to run Windows Forms code
> with the following error:
> From: System.Windows.Forms, at: Void .ctor(), Error Message: The type
> initializer for
> 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an
> exception.
> Question First: The main question I had for the Mono list is this.
> Is it possible to have mono run Windows Forms code without trying to
> open X11 (I.e. headless mode)?  What triggers mono to request an X11
> display? Is it the project type?  Is it the call to an object that
> inherits from a Windows Forms control?  I don’t need to see the form,
> but if I’m using BackgroundWorkers, I need the form's event handler,
> don’t I?

BackgroundWorker does not depend upon System.Windows.Forms, i.e.
it can use it headless.

The exception you're experiencing is caused by the synchronization
context set and used by WinForms.

Supposing that you don't need any kind of synchronization, you
may want to replace the synchronization context with a simple

I don't know if the most simple one 
would be enough or if you have to subclass it. Have a look
at its sources and at


More information about the Mono-list mailing list