I have a VB6 DLL being accessed from some C# code.
Using the compiled & registered VB6 DLL there is no problem. But when I load the VB6 source into the VB6 IDE and run the project, the next run of the C# code will fail with the error below.
Stopping the running DLL in the VB6 IDE will again allow the C# program to work from the compiled DLL.
The VB6 DLL is compiled with binary compatibility.
The error message I receive in C# is:
An unhandled exception of type 'System.InvalidCastException' occurred in appname.exe Additional information:
Unable to cast COM object of type 'dllname.classnameClass' to interface type 'dllname._classname'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{D8AB6D65-F5E7-4B9C-A039-67DDC630E5F7}' failed due to the following error:
Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (
TYPE_E_CANTLOADLIBRARY
)).
Specifically this error occurs when the C# code tries to access any part of the interop object which actually comes from the underlying COM object. But accessing .NET Object
-derived things like .ToString()
work fine on that object.
Why am I getting this error?
Furthermore:
If I compile the C# code when the VB6 code is NOT running, it builds fine. But compiling when the VB6 code IS running, then I get an error:
BC30002 dllname.classname is not defined.
Thanks
Maybe someone else will have a deeper understanding, but this is what I eventually figured out:
The quandary is that admin rights are needed for certain build operations (specifically, registering COM DLLs automatically). So that was the pitfall; ultimately I had to repeatedly switch between admin/non-admin settings for both tools in order to code-test-modify...
Note - when I've debugged in a different scenario where the program is a VB6 EXE debugging into C# code, this was never a problem. Everything could run in as admin no problem.
User contributions licensed under CC BY-SA 3.0