Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调试com可见dll托管代码_C#_Visual Studio_Debugging_Dll_Comvisible - Fatal编程技术网

C# 调试com可见dll托管代码

C# 调试com可见dll托管代码,c#,visual-studio,debugging,dll,comvisible,C#,Visual Studio,Debugging,Dll,Comvisible,我已经编写了一个COM可见dll,它将从本机Win32程序调用。出于调试目的,我在包含dll的解决方案中添加了一个简单的WinForms客户端 现在,当我在dll中设置一个断点时,该断点被命中,但我无法单步执行代码:调试器总是跳转到dll中的下一个断点,或调用dll后客户端中的第一行代码 如何让调试器单步执行dll代码 我认为这可能是启用我的代码选项,但这并没有设置 更新 jdv建议在项目属性中设置启用非托管代码调试,但没有达到预期效果 谢谢,Miel。以下是我执行的步骤,这些步骤使我能够成功调

我已经编写了一个COM可见dll,它将从本机Win32程序调用。出于调试目的,我在包含dll的解决方案中添加了一个简单的WinForms客户端

现在,当我在dll中设置一个断点时,该断点被命中,但我无法单步执行代码:调试器总是跳转到dll中的下一个断点,或调用dll后客户端中的第一行代码

如何让调试器单步执行dll代码

我认为这可能是启用我的代码选项,但这并没有设置

更新 jdv建议在项目属性中设置启用非托管代码调试,但没有达到预期效果


谢谢,Miel。

以下是我执行的步骤,这些步骤使我能够成功调试作为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");
        }
    }
}
regasm.exe /codebase COMTest.dll
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]);
    }
}
使用强密钥并注册为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");
        }
    }
}
regasm.exe /codebase COMTest.dll
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]);
    }
}
注册COM对象后,您可以在新的Visual Studio实例中创建新的控制台应用程序来测试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");
        }
    }
}
regasm.exe /codebase COMTest.dll
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行上放置断点并运行应用程序。点击断点后,打开Ctrl+D M并确保为COM程序集加载了符号:

现在,如果按F11键,则可以进入COM类进行调试


备注:您也可以直接打开包含Foo类的.cs文件,并直接在其中放置断点。同样重要的是为程序集加载符号,或者当您放置断点时,Visual Studio会告诉您不会命中此断点。

以下是我执行的步骤,这些步骤使我能够成功调试作为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");
        }
    }
}
regasm.exe /codebase COMTest.dll
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]);
    }
}
使用强密钥并注册为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");
        }
    }
}
regasm.exe /codebase COMTest.dll
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]);
    }
}
注册COM对象后,您可以在新的Visual Studio实例中创建新的控制台应用程序来测试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");
        }
    }
}
regasm.exe /codebase COMTest.dll
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行上放置断点并运行应用程序。点击断点后,打开Ctrl+D M并确保为COM程序集加载了符号:

现在,如果按F11键,则可以进入COM类进行调试


备注:您也可以直接打开包含Foo类的.cs文件,并直接在其中放置断点。同样重要的是为程序集加载符号,或者当您放置断点时,Visual Studio会告诉您该断点不会被命中。

发布了一个VS2008 SP1之后的修补程序,它解决了许多调试问题。KB文章,热修复程序下载。

发布了VS2008 SP1后的热修复程序,解决了许多调试问题。KB文章,热修复程序下载。

链接:@hans:成功了。如果你把你的评论变成一个真实的答案,你就会得到奖励。别让它掉到腰部。林克:@hans:这就成功了。如果你把你的评论变成一个真实的答案,你就会得到奖励。别让它跑到腰部去。