Debug com visible dll managed code
I have written a COM visible dll, which will be called from a native Win32 program. For debugging purposes I added a simple WinForms client to the solution containing the dll.
Now when I set a breakpoint in the dll, that 开发者_开发百科breakpoint is hit, but I can't step through the code: the debugger always jumps to the next breakpoint in the dll, or the first line of code in the client after the call to the dll.
How can I get the debugger to step through the dll code?
I thought it might be the "Enable Just My Code" option, but that is not set.
Update jdv suggested setting "enable unmanaged code debugging" in the project properties, but that didn't have the desired effect.
Thanks, Miel.
Here are the steps I performed and which allowed me to successfully debug a .NET assembly exposed as COM component:
Start by creating a class library containing a class that will be exposed as COM object:
namespace COMTest
{
using System;
using System.Runtime.InteropServices;
public interface IFoo
{
void Bar();
}
[ComVisible(true)]
public class Foo : IFoo
{
public void Bar()
{
Console.WriteLine("Bar");
}
}
}
Sign the assembly with a strong key and register as COM object:
regasm.exe /codebase COMTest.dll
Once the COM object is registered you may create a new console application in a new Visual Studio instance to test the COM object:
class Program
{
static void Main()
{
var type = Type.GetTypeFromProgID("COMTest.Foo");
var instance = Activator.CreateInstance(type);
type.InvokeMember("Bar", BindingFlags.InvokeMethod, null, instance, new object[0]);
}
}
Place a breakpoint on the InvokeMember
line and run the application. Once the breakpoint is hit open the Modules Window (Ctrl+D M) and make sure that symbols are loaded for the COM assembly:
Now if if you press F11 you can step into the COM class to debug.
Remark: You can also directly open the .cs file containing the Foo
class and directly place a breakpoint there. Once again the important thing is to have the symbols loaded for the assembly or when you place your breakpoint Visual Studio will tell you that this breakpoint won't be hit.
There was a post VS2008 SP1 hotfix released that solves a number of debugging problems. The KB article is here, the hotfix download is here.
精彩评论