Archive for the ‘MonoDevelop’ Category

Specifying Custom NUnit Runner in MonoDevelop


I just discovered that the NUnit Add-In in MonoDevelop has a nice although undocumented feature: you can specify a custom test runner in the .csproj file, either as an executable or as a type. If you have the NUnit.Runners nuget package installed in your solution/project and you want MonoDevelop to run the unit tests with nunit-console.exe instead of the built-in runner, you can add the following to your .csproj file:


Now when you run your unit tests in MonoDevelop they will be run by nunit-console. This is useful when your unit tests make use of features that the NUnit Add-in doesn’t support yet, like ActionAttributes.

The other tags that are supported are:

  • TestRunnerArgs: Allows to specify additional command line arguments to the TestRunnerCommand
  • TestRunnerType and TestRunnerAssembly: allow to specify a test runner class/type and the assembly where to find this type.

If both TestRunnerArgs and TestRunnerType are specified, TestRunnerArgs takes precedence.

Tracking undisposed objects


Every so often I come across a crash or a hang in my project or unit test that is caused by missing dispose calls. This is especially true if a managed object holds references to COM objects and even more so if it’s not thread-safe. Since garbage collection runs on a different thread the finalizer gets called on that thread as well, often causing trouble.

Often it’s not obvious which object doesn’t get disposed and causes this behaviour. Usually it takes me several days to find the culprit and fix the bug. Over the years I developed some strategies that get refined over time. When I came across this situation again last week I decided to create a tracker class that keeps track of the created and disposed objects together with a counter that identifies the creation call. This made it easier to add a method call to the constructor and the Dispose() method but it still required quite a bit of repetitive work to temporarily add those calls to the c’tor and Dispose methods.

On the weekend I stumbled upon the nuget package Fody; this helped an idea to materialize that I had for a few days. As a consequence I created a fody addin, Undisposed.Fody, that injects calls to my tracker class into the constructor and dispose methods of all types in the current assembly. The fody addin gets run during the build of the current project. I also created a standalone application that allows to hack an existing assembly.

The modified assembly outputs a line on the console if an object gets created and when it gets disposed, and it dumps all undisposed objects. Hopefully this will give some hints which object creation calls to inspect.

The source code is available on github, and there is also a nuget package.

Remote Debugging with MonoDevelop


This morning I tried to debug some Mono code in a Ubuntu 13.10 Saucy virtual machine that doesn’t have all the developer tools installed. Miguel de Icaza recently blogged about remote debugging, but it took a bit of fiddling to get it working. Here are my findings:

In the VM start your application with

mono --debug --debugger-agent="address=,transport=dt_socket,server=y" \

The IP address is the address of the VM, transport is a required argument, dt_socket seems to be the only allowed option. It is important to specify the full path to your managed application otherwise you’ll get an error that the application can’t be found.

Then on your developer machine set the environment variable MONODEVELOP_SDB_TEST and start MonoDevelop:


This adds a new menu item that allows to start a remote debugging session, under Run -> Run With -> Custom Command Mono Soft Debugger. This opens a dialog window; enter the IP address of your VM ( and the port (10000) and start the session with the Connect button. This starts the application in the VM. Debugging works the same as if you would start the app locally. Great!

Lost Menu in Monodevelop in Unity


Recently I got a new desktop computer on which I installed Ubuntu 11.04 Natty with the Unity UI. Yesterday I compiled Monodevelop 2.6 beta 3 (using the scripts described here) which worked fine – only when I run monodevelop the menu can’t be found anywhere: there is no menu in the monodevelop window nor in the global menu bar. Since it’s pretty hard to do any work without a visible menu, I decided to try to get this fixed. (more…)

Debug.Assert and Mono


On Microsoft’s .NET implementation on Windows a Debug.Fail() (which is equal to a Debug.Assert(false)) when run on a debug build displays a dialog box with the options Abort, Retry, Ignore. When run in the debugger it also displays the call stack.

On Mono however no dialog box shows; it behaves the same as when the user pressed ‘Ignore’. What’s worse is that it doesn’t display the call stack by default, even when run in debugger. This doesn’t give any hint if an exception happened. (more…)

Building MonoDevelop from SVN


Yesterday I managed to build MonoDevelop from SVN source. I had done it before but had forgotten how to do it, and there are no fool-proof instructions on what you need to build. (more…)