Hi, I have a C# application using C++ COM object both build on a 32 bit machine. Now I have to run them on a 64 bit machine. I registered the COM object. A corresponding entry was created in the register under computer\hkey_classes_root\wow6432node\clsid{xxx}. However, when I try to run the application it says that |"Retrieving the COM class factory for component with CLSID {xxx} failed due to the following error: 80040154.". As I understand, the error code means that the class is not registered. Please, help!!! Thanks
The C# app may have been compiled with the Any CPU target, which will run as in 64-bit mode on an x64 machine. 64-bit processes can't access 32-bit processes.
In Visual Studio, you can force it to compile as a 32-bit only application. It's in the Project properties, Build tab, Platform target dropdown. Set it to x86
.
There may be other ways of forcing it to run as a 32-bit application, but I'm not familiar with them.
I don't think you can run a 32bit app natively on a 64bit machine. You need to compile your app as 64bit binary or run it under an Emulator (like WOW64 on windows). If your app (build in 64bit binary) uses any external dlls, you also need the 64bit version of all those dlls.
Here's a good reference:
http://searchwindowsserver.techtarget.com/tip/0,289483,sid68_gci1220022,00.html
Edit:
If you go to your Project's Properties -> Build, change Platform's Target from "Any CPU" to X86. See if this helps.
Or you need to register your dlls: http://riteshk.blogspot.com/2007/05/retrieving-com-class-factory-failed-due.html
The first answer above is the correct answer. You cannot run a CPU ANY target application on 64 bit Windows if you reference a 32 bit COM component. It will not load.
What is happening is that the JIT is seeing CPU ANY and promoting your App to 64 bit. But there is no 64 bit version of the com control and hence you get the not registered error.
This is a big problem for people who use Microsoft Access for their database. There is no 64 bit version of Access, so when they see the error they think they need a 64 bit runtime (doesn't exist). You have to flag your app as 32 bit only in order to use the Access runtime.
This is a poor choice (IMHO) - find a better component that has a 64 bit version, or go 100% managed code.
I don't like to every tag apps as 32 bit only unless they REALLY need it.
The .NET runtime automatically runs the application as 64-bit and it no longer can load the 32-bit COM component into its process.
That's very easy to workaround if the COM component has Automation-compatible interface. Create a COM+ application (Control Panel->Administrative Tools->Component Services) and add the component into it. This way you'll force the creation of the component in a separate process and you will no longer care that your client application run as a 64-bit application.