COM接口/classreturns"object has no properties or methods"错误
COM interface / class returns "object has no properties or methods" error
我正在尝试开发一个计算引擎,并将实现的 classes 作为 COM 对象公开在这个 Article 之后。公开的 DLL(Com 对象)将由第三方应用程序使用。一些由 VB6 实现的旧 DLL 现在可以正常使用和工作。
虽然在命令提示符中通过 RegAsm 命令注册了最终的 DLL,但 COM 对象在目标应用程序中变得可见,但我收到了
的错误消息
"Failed to create object", "Object has no properties or methods".
目前为止我尝试过的,除了下面的代码,如下所列:
- ComVisible 在 AssemblyIfo.cs[=61= 中设置为 true ]
- 在构建选项中选中"Register for COM interop"
- 在 classe/interface and/or 方法
上设置 [ComVisible(true)] 属性
- 在 classe/interface and/or 方法上设置 [DispId(0)] 属性 不同的值 !!
- 在 classe/interface and/or 方法上设置 [ProgId] 属性
- 所有方法和 classes 都定义为 public 成员
- 对 class with/without 界面进行了上述所有操作
- 对 class with/without 事件接口尝试了上述所有操作
我在这里创建了一个示例代码作为示例,如有任何进一步的帮助,我们将不胜感激:)
using System;
using System.Runtime.InteropServices;
namespace project_name
{
[Guid("EAA4976A-45C3-4BC5-BC0B-E474F4C3C83F")]
[ComVisible(true)]
public interface ComClass1Interface
{
[DispId(0)]
[ComVisible(true)]
double calc();
}
[Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ComClass1Events
{
}
[Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(ComClass1Events))]
public class ComClass1 : ComClass1Interface
{
public double calc()
{
return 13;
}
}
}
使用 RegAsm 命令注册 DLL,以便在 COM 对象上列出。
Com 对象对目标应用程序可见。
当尝试 select 实现的方法时,我遇到了这些错误:-/:
我正在使用 Visual Studio 2019、C#、.NET Framework 4.0,目标应用程序是 运行 on Windows Server 2008 R2 并且安装了 .NET Frameworks 3.5、4.6。
通过这些操作解决的问题:
- 程序集应使用强名称进行签名(我使用了 Visual Studio 签名工具)
- COM 对象应注册
regasm path/dll-name.dll /codebase /tlb /nologo
我正在尝试开发一个计算引擎,并将实现的 classes 作为 COM 对象公开在这个 Article 之后。公开的 DLL(Com 对象)将由第三方应用程序使用。一些由 VB6 实现的旧 DLL 现在可以正常使用和工作。
虽然在命令提示符中通过 RegAsm 命令注册了最终的 DLL,但 COM 对象在目标应用程序中变得可见,但我收到了
"Failed to create object", "Object has no properties or methods".
目前为止我尝试过的,除了下面的代码,如下所列:
- ComVisible 在 AssemblyIfo.cs[=61= 中设置为 true ]
- 在构建选项中选中"Register for COM interop"
- 在 classe/interface and/or 方法 上设置 [ComVisible(true)] 属性
- 在 classe/interface and/or 方法上设置 [DispId(0)] 属性 不同的值 !!
- 在 classe/interface and/or 方法上设置 [ProgId] 属性
- 所有方法和 classes 都定义为 public 成员
- 对 class with/without 界面进行了上述所有操作
- 对 class with/without 事件接口尝试了上述所有操作
我在这里创建了一个示例代码作为示例,如有任何进一步的帮助,我们将不胜感激:)
using System;
using System.Runtime.InteropServices;
namespace project_name
{
[Guid("EAA4976A-45C3-4BC5-BC0B-E474F4C3C83F")]
[ComVisible(true)]
public interface ComClass1Interface
{
[DispId(0)]
[ComVisible(true)]
double calc();
}
[Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ComClass1Events
{
}
[Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(ComClass1Events))]
public class ComClass1 : ComClass1Interface
{
public double calc()
{
return 13;
}
}
}
使用 RegAsm 命令注册 DLL,以便在 COM 对象上列出。
Com 对象对目标应用程序可见。
当尝试 select 实现的方法时,我遇到了这些错误:-/:
我正在使用 Visual Studio 2019、C#、.NET Framework 4.0,目标应用程序是 运行 on Windows Server 2008 R2 并且安装了 .NET Frameworks 3.5、4.6。
通过这些操作解决的问题:
- 程序集应使用强名称进行签名(我使用了 Visual Studio 签名工具)
- COM 对象应注册
regasm path/dll-name.dll /codebase /tlb /nologo