c# - 无法将 C# dll 注册为 COM 组件,模块已加载但未找到入口点 DLLRegisterServer

标签 c# .net com regsvr32

<分区>

我创建了一个类并使其可见:

[ComVisible(true)]
    [Guid("FD909333-3CD0-477F-8A7E-B8045B0B84EC")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("TestComApp.TestApp.TestClass")]
    public class TestClass:ITestCom
    {
        public int Add(int a, int b) { return a + b; }
    }

同时接口(interface)设置为COM可见:

[ComVisible(true)]
    [Guid("26567B41-15DB-4EE2-A277-357EAE96BF6A")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    interface ITestCom
    {
         int Add(int a, int b);
    }

但是当我尝试注册 DLL 时

regsvr32 /i TestComApp.dll

我收到以下错误“模块已加载但未找到入口点 DLLRegisterServer”

enter image description here

最佳答案

要注册 .NET DLL,您需要使用 Regasm.exe 而不是 regsvr32.exe。 Regasm.exe 位于 C:\Windows\Microsoft.NET\Framework\v4.0.30319(或类似位置,具体取决于 .NET 版本)。

还要确保指定/codebase 选项,或使程序集具有强名称,否则 COM 将无法找到 DLL。

关于c# - 无法将 C# dll 注册为 COM 组件,模块已加载但未找到入口点 DLLRegisterServer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31603558/

相关文章:

c# - 如何在 Stimulsoft 报告中使用数据对象?

c# - 设置 Backgroundworker MVVM,更新 Progressbar

c# - 具有相同签名的成员已经定义了不同的类型约束

C# - 如何从引用其他对象类型的 "object"类访问成员变量

c# - 有没有办法确定哪个组件实际在 .NET 应用程序中分配内存?

c# - 区分子类和父类对象?

python - 从Word.Application对象获取Document对象时,其成员不会从gencache缓存中填充,而VBSEdit可以获取它们

.net - Excel 从两个不同的 AppDomain 调用 .NET 自动化服务器?

.net - 使用OCX无需注册

c# - 如何将 FlowDocument 添加到 StackPanel?