Search code examples
c#vbscriptcominterop

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


I've created Class library project with next code and settings:

using System.Runtime.InteropServices;

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

Also checked

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

and

'Register for COM interop' in Properties/Build

In my VBscript I am getting exception

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

when trying to create object from dll:

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

Solution

  • You might be using regasm.exe to add the Class into the registry but where in the registry?

    Problem is we have the complication of dealing with both 32-bit and 64-bit architectures, so couple of things spring to mind.

    How are you running the script

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

    If you are using the default wscript.exe Windows Scripting Host to run the script then it will default to OS architecture which in most modern installations will be 64-bit OS.

    If regasm.exe isn't registering the Class with the 64-bit registry then CreateObject will never find the prog id MyDll.TestClass.

    Check through this article and see if you can see the Class in the registry, it details the various locations to check for both 32-bit and 64-bit.


    Useful Links