Archive for the ‘.NET’ 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.

Cross-Platform Development and Data Type Sizes


One of the problems when developing cross-platform apps is the question how long the intrinsic data types are on the different platforms. A while ago I created a table with the sizes of the different data types on 32- and 64-bit Windows and Linux, both for C++ and C#/.NET. (more…)

Location of special folders on Linux


One thing that always confuses me is how the special folders of Environment.SpecialFolder translate into real directories. Some are really obvious, especially on Windows, but on Mono on Linux it’s not so obvious. So I wrote a little app that tells where those folders are. (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…)

IME and TSF and bugs when typing Chinese


Quite a while ago I investigated some problems we were having with Chinese IME with one of our applications. Since that was new stuff for me I made some notes but never came around to finish this blog entry.


Using C# 3.0 Features with .NET 2.0


With Visual Studio 2008 Microsoft also updated the C# language. C# 3.0 brings several new and useful features that are described in a MSDN article.

Visual Studio 2008 will always compile with the new C# 3.0 compiler even when you select .NET Framework 2.0 as target framework in your project.

This raises an interesting question: is it possible to use the new features of C# 3.0 even when you use .NET Framework 2.0? And which new features can you use? (more…)

Strong-name Unsigned Nothings


A while back I wrote about how to access internal methods in unit tests. When I actually tried to do it, I got the following error message:

error CS1726: Friend assembly reference 'MyDllTests' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations. (more…)

Multi-threading in .NET and COM objects

Some things I learned about using COM objects in multi-threaded managed applications: (more…)

Debugging into .Net Source Code


Microsoft had announced last October that they will make the source code for .Net available with Visual Studio 2008. (more…)