Archive for the ‘COM’ Category

Tracking undisposed objects

2014/10/29

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.

IME and TSF and bugs when typing Chinese

2009/01/16

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.

(more…)

Multi-threading in .NET and COM objects

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

NUnit hangs with SQLNCLI

2007/09/14

The last couple of days I was hunting an interesting bug (FWC-16). During our build process we’re running automated unit tests with NUnit. This usually works pretty nice – until suddenly one of my co-workers got trouble. The build process just hang while running one particular test fixture. No crash, no errors, it just never finished. (more…)