Debugging With MWF

This guide builds on the sample presented in Guide: Porting Winforms Applications. Please refer to it if you need background information on the project being used.

When debugging Winforms applications for Mono, many times it is easier if you can debug with Managed.Windows.Forms (MWF - Mono’s version of System.Windows.Forms), instead of Microsoft’s System.Windows.Forms. To accomplish this, you can load the MWF project file into your solution, which will allow you to debug into Mono’s MWF code. This guide illustrates the steps necessary to do this.

Getting the MWF Project

Download Mono’s source tree from:

https://github.com/mono/mono

Setting up the Environment

Mono’s System.Windows.Forms implementation resides in the mcs/class/Managed.Windows.Forms folder of the Mono source tree, and it includes Visual Studio project files for both Visual Studio 2003 and 2005. These are used to debug MWF for the 1.1 (SWF.csproj - VStudio 2003) and 2.0 (SWF2k5.csproj - VStudio 2005) profiles.

To debug an application using Mono’s Winforms library instead of the MS.Net version, we load into the solution the project file, and change the application references to point to the library generated by the project.

Mwf adding.png

With the project loaded in the solution, all we need now is to change any references to the System.Windows.Forms assembly so they point to our newly loaded project. Of the 4 projects that comprise the NClass solution, only 2 reference SWF - GUI and GUI.Diagram - so we remove those references and add new ones to the SWF2k5 project.

Mwf reference.png

Building

Another nice feature of this setup is that it will show us exactly which methods of MWF the project uses that are not implemented. Using our NClass example before we modified it, building gives us this:

Nclass builderrors.png

Nclass builderrors2.png

Since GUI depends on GUI.Diagram, you’ll have to fix or comment the build errors on GUI.Diagram first, before going on to GUI. The list of errors above shows errors for both projects, and I had to temporarily comment all the lines with errors on GUI.Diagram so that I could see the errors on the GUI project.

Note that this setup only replaces System.Windows.Forms, and not other references like System or System.Drawing. The Microsoft version of these will still be used. This can be useful for narrowing down a bug to MWF and not one of its dependencies. Also, you cannot use the visual designers in Visual Studio while using this trick, as they are linked to .Net’s System.Windows.Forms and not Mono’s Managed.Windows.Forms.