COMException "Class not registered" on 64-bit Windows
Having finally got myself running live on Windows 7, this morning it was time to fix the one problem remaining - Visual Studio 2008 throwing the COMException "Class not registered" (REGDB_E_CLASSNOTREG) when trying to call InitializeComponent on a form which has an ActiveX control on it:
System.Runtime.InteropServices.COMException (0x80040154): Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)) at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid) at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid) at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid) at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid) at System.Windows.Forms.AxHost.CreateInstance() at System.Windows.Forms.AxHost.GetOcxCreate() at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state) at System.Windows.Forms.AxHost.CreateHandle() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.AxHost.EndInit() at OCXWrappers.TXTextControl.InitializeComponent() in C:\Users\...\Form1.Designer.vb:line 42
Hunting around Google turned up nothing (the OCX was definately registered correctly), but I did twig after a few minutes... The ActiveX control in question was 32-bit, whereas Visual Studio defaults to compile to "Any CPU" and I was now running 64-bit Windows.
Solution: Go into the Project Properties, Compile tab and click "Advanced Compile Options...". Change "Target CPU" to x86, click OK, save and try again.
Presumably this is the same problem as others have had when trying to run on Windows XP / Server 2003 and above when the customer is running 64-bit and the development environment is 32-bit.Theo Gray on October 5, 2009 | Permalink | Comment