How to debug .NET Libraries in COM Environment

By | June 7, 2010

It is really easy to debug COM registered .NET libraries. The only thing you have to do is calling the “Debug.Assert();” method in the .NET code.

See the code:

[ComVisible(true)]
public class Lib
{
    public string HelloWorld()
    {
        Debug.Assert(false, "Debug!");
        return "hello world";
    }
}

When you call the method for instance from a VBScript the “Debug” screen should appear.
When you click “retry” the VS.NET IDE starts.

VBS Code:

Set obj = CreateObject("ClassLibrary1.Lib")
msgbox obj.HelloWorld()

Here the Assert Message:
Assert Message

And here inside the IDE:
Debug IDE