Blog
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.


Reader Comments
Skip to form
January 14, 2010
,Andy Bruce says:Yup, that was my problem too. Freaking annoying it is, too! After all this time to have to think about COM and 32-bit code, ugh.
February 17, 2010
,Mark Beckwith says:I am on my knees thanking God for Theo Gray. Also cursing MS a little bit.
February 22, 2010
,Bob says:Thanks Very Much for this, its appreciated !!
February 24, 2010
,Nick Olsen says:Thanks for this! Solved my problem! [pingback]
May 2, 2010
,johany says:thanks
you solved it nice and easy
May 10, 2010
,Mark says:Holy cow, I spent a number of hours on this. Thanks so much!
May 27, 2010
,Faraday says:Thank you, this solved my problem.
July 1, 2010
,Vinu nair says:thank you very much, @ the end of the day I am happy that the issue is sorted out.