0x800a01ad - Microsoft VBScript runtime error: ActiveX component can't create object

0x800a01ad - Microsoft VBScript runtime error: ActiveX component can't create object

我已经使用下一个代码和设置创建了 Class 库项目:

using System.Runtime.InteropServices;

namespace MyDll
{
    [ComVisible(true)]
    public class TestClass
    {
        [ComVisible(true)]
        public string[] SomeFunc(string path)
        {
            return new[] {"1","7","9"};
        }
    }
}

也检查了

'Make Assembly COM-Visible' in Properties/Application/Assembly information

'Register for COM interop' in Properties/Build

在我的 VBscript 中出现异常

"0x800a01ad - Microsoft VBScript runtime error: ActiveX component can't create object: 'MyDll.TestClass'"

尝试从 dll 创建对象时:

Dim result
Dim myObj
Set myObj = CreateObject("MyDll.TestClass")
Set result= myObj.SomeFunc("a")

您可能正在使用 regasm.exe 将 Class 添加到注册表中,但在注册表中的什么位置?

问题是我们在处理 32 位和 64 位架构时很复杂,所以有几件事 spring 需要注意。

你运行脚本如何

Dim result
Dim myObj
Set myObj = CreateObject("MyDll.TestClass")
Set result= myObj.SomeFunc("a")

如果您使用默认的 wscript.exe Windows 脚本主机到 运行 脚本,那么它将默认为 OS 架构,在大多数现代安装中将为 64 -bit OS.

如果 regasm.exe 没有在 64 位注册表中注册 Class,那么 CreateObject 将永远找不到程序 ID MyDll.TestClass

检查 并查看是否可以在注册表中看到 Class,它详细说明了检查 32 位和 64 位的各个位置。


有用的链接

  • @cynic answer to How to do RegAsm so that it cover 32-bit and 64-bit?