I try to create the same COM object instance from .Net Framework 4.0 console and windows forms application.
var t = Type.GetTypeFromProgID("MyProgID");
dynamic req = Activator.CreateInstance(t);
While my console application tells me:
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM cla
ss factory for component with CLSID {CF2D8AF3-287C-4107-8790-D37F169E2475} faile
d due to the following error: 80040154 Class not registered (Exception from
HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Windows forms application creates instance without exceptions.
What can be wrong here?
In both cases I have [STAThread] attribute applied to "Program" class.
I have found the issue.
COM objects work only in x86 environment. While my windows forms application was builded for x86 only, my console was "Any CPU" that provided error in x64 environment.
After I changed Platform Target for console application everything comes OK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With