Facing issue in using a COM library

kamleshm

Member
Joined
Nov 18, 2021
Messages
10
Programming Experience
5-10
Hello All
I have a C# project developed in dotnet framework 4.5 , windows 10 machine. The project "adds a reference" to the COM library , that has been developed in VB6
The project compiles properly but when it is run , I get the exception as below


C#:
System.TypeInitializationException:
'The type initializer for 'CcWanPipesClientLib.ClearcaseHelper' threw an exception.'

innerexception:
BadImageFormatException: Retrieving the COM class factory for component with CLSID {B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

On different links and forums , dllsurrogate method " Using a 32bit COM object in a 64bit environment" , I followed the same
But still the exception comes.

Please guide me through it as I am new to both C# and COM
 
And worse case, compile your code to target 32-bit instead of 64-bit. Why pay the price of thunking from 64-bit down to 32-bit when you don't need to.
 
I ported the VB6 code to C++ and am able to create and register the COM dll in 64 bit . But I am still facing the same issue . Any insights would be of great help
 
Sounds like a bug in the way you are registering your COM object. This is not a C# problem.

Anyway, post your your COM registration code. It looks like your may not be pointing to your COM DLL properly.

And be sure to post the error again. Is it the same exact error, or some other error?

As an aside, if your took time to to port the VB6 code to C++, why not go the extra step to use C++/CLI and IJW?
 
I have attached a gif file and a png file . The gif file displays the COM library that has been referenced by a C# Code ( CCAutomation ). The CCAutomation creates a wrapper API over the COM . The API has been called in another C# project where the exception is thrown ( exception is in png file )
Exception:
 

Attachments

  • vsissue_exception.PNG
    vsissue_exception.PNG
    32.7 KB · Views: 12
No. Don't send screenshots of code. Post the code as text in code tags.
 
Exception:
System.TypeInitializationException:
'The type initializer for 'CcWanPipesClientLib.ClearcaseHelper' threw an exception.'

innerexception:
BadImageFormatException: Retrieving the COM class factory for component with CLSID {B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

Exception has been shared
 
Thank you, and now the code that writes to the registry to register your COM object?
 
The video you showed on post #7 shows how you are adding a reference to the COM library. That is not how what I'm asking about. I'm asking about how the COM library is registered on the machine.

In post #4, you said that you re-wrote the VB6 code to C++. What does the C++ code look like? Specifically, what does the DllRegisterServer() look like for the COM object?
 
Not directly related to your problem, but recall that .NET Framework 4.5 is out of support. You need at least 4.6.2 to still be in support by Microsoft.
 
The C++ code is now a copyright code for my company , still I have added the "Dllregisterserver" part here
C#:
STDAPI DllRegisterServer(void)
{
    // registers object, typelib and all interfaces in typelib
    HRESULT res = _Module.RegisterServer(FALSE);
    if (FAILED(res))
        return res;

    TCHAR filename[_MAX_PATH];
    GetModuleFileName(_Module.m_hInstResource, filename, _MAX_PATH);

    USES_CONVERSION;
    CalBSTR bfilename(T2OLE(filename));

    CComPtr<ITypeLib> pTypelib;

    res = LoadTypeLib(bfilename, &pTypelib);
    if (FAILED(res))
        return res;

    return RegisterTypeLib(pTypelib, bfilename, 0);
}
 
That is still opaque to us, since we can't see how _Module.RegisterServer(FALSE) works.
 
Let's try a different approach. Export the subkey for your COM object's CLSID into .REG file, then post the contents of the .REG file in code tags here.
 
Back
Top Bottom