Archive for the ‘Visual Studio’ Category

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.

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…)

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…)

C++ Project stopped compiling in VS08 and mixing 8.0/9.0 compiler and linker


Recently I ran into a problem in Visual Studio 2008: a C++ project suddenly didn’t compile anymore. I had successfully compiled it before. (more…)

Visual Studio 2008 – Experiences and Compatiblity with VS 2005


So I went to Microsoft’s Installfest and got a copy of Visual Studio 2008 which I installed on my desktop machine. Here are some of the things I found:

  • Visual Studio 2008 updates the .csproj files when it loads a project. However, it can still be read by Visual Studio 2005 which means not all people in a team have to switch to the new version of VS at the same time. VS08 adds a (more…)

GTK# and Visual Studio 2005


The Windows installer for GTK# comes with project templates for Visual Studio 2005. However, they don’t work out of the box.

You have to modify the .vsz files (more…)

WDS add-in for Visual Studio 2005


A while ago I installed Windows Desktop Search (WDS) both on my machine at work and at home. I had looked at several desktop search engines and for reasons I don’t remember I decided that WDS would best fit my needs.

This morning I got tired of waiting for the file search in Visual Studio 2005 to search for all the files in my project’s directory tree, so I googled if there is something that would allow VS to make use of WDS (more…)