下面是我執行,並且其中所述步驟允許我成功地調試暴露爲COM組件.NET組件:
開始通過創建包含將被公開爲COM對象類的類庫:
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用強密鑰並註冊爲COM對象:
regasm.exe /codebase COMTest.dll
一旦COM對象被註冊,您可以CRE吃了一個新的Visual Studio實例一個新的控制檯應用程序來測試COM對象:
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]);
}
}
放在InvokeMember
行斷點和運行應用程序。一旦命中斷點打開Modules Window(按Ctrl + DM),並確保符號已加載的COM組件:
現在,如果你按F11可以步入COM類來調試。
備註:您也可以直接打開包含Foo
類的.cs文件,並直接在其中放置斷點。再次重要的是要爲程序集加載符號,或者當您放置斷點時,Visual Studio會告訴您這個斷點不會被擊中。
鏈接:http://stackoverflow.com/questions/2026510/visual-studio-debugger-skips-over-breakpoints – 2010-09-11 18:49:36
@hans:這個伎倆。如果你把你的評論變成真實的答案,你會得到獎勵。讓我們不要讓它走到腰部。 – Miel 2010-09-13 07:27:16