Search code examples
c#comvb6runtime-errorcreateobject

VB6: Run-time error 424 When Calling CreateObject


I created a C# COM accessible dll that I want to consume in VB6 I was able to consume in VB6 my COM object with a hard reference to the TLB. What I am trying to do now is to remove this reference and load it dynamically I am creating it as follows:

Dim keylok As Object
Set keylok = CreateObject("MyClassLib.MyObject")

I get the Run-time error 424 "Object Required" once I hit the second line. But when I create it as follows:

Dim keylok As MyObject
Set keylok = CreateObject("MyClassLib.MyObject")

It works fine. I am not sure why would that make a difference. Anyway I cannot use the second one because I would still need to have the physical reference.

I tried also as a sort of debugging to write to file in my COM object constructor to if it really gets called. And yes it does, I'm even able to call other methods in my COM object sucessfully inside the constructor.

I was even able to load dynamically and consume it from another C# app using:

dynamic myObj = Activator.CreateInstance(Type.GetTypeFromProgID("MyClassLib.MyObject"));

Did any one encounter something like that before?


Solution

  • I found the solution with the help of @rskar input. So, I thought I'm gonna answer my question, in case any one faces the same problem.

    My object didn't impelement IDsipatch. So all I had to do it to decorate my C# COM interface with InterfaceType(ComInterfaceType.InterfaceIsDual) So it implements both IUnknown and IDispatch. Originally it was decorated with InterfaceType(ComInterfaceType.InterfaceIsIUnknown)