Skip navigation.

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.

November 12, 2010, JFinger says:

Thank you, thank you, thank you.
"Any CPU" was all over the place, and I had a 32-bit ActiveX control on a Windows Form (VS2005 C#) and needed this code to go on both 32-bit and 64-bit platforms. The x86 did the trick, although I am peeved that it created a whole new configuration in VS2005, but I can deal with it because it finally works!!! Thank you again!!!

February 17, 2011, Bruce says:

You just ended hours and hours of frustration!! Thanks!!!

April 28, 2011, amit patil says:

Hi,
I m using VSTA 2 ( Visual studio tools for applications ) and having the same problem.
As per your solution i need to change target platform, but there is no option to change target platform in VSTA.
Your help appreciated.
Amit

May 17, 2011, Robbo says:

Hi,

I have VB.NET VS2008 and VS2010 and I cannot find any reference to TargetCPU in the advanced compile options. Is this because I only have the Express editions?

I cannot use an ocx on Win 7 64 bit even though it has been successfully registered using sysWow64\regsvr32.exe.

Any suggestions please?

May 17, 2011, Robbo says:

Hi again,
I found the answer to my question here:
http://forums.create.msdn.com/forums/t/4377.aspx#22601


  1. In VS Express 2005/8/10 VB Net or C", go to Tools -> Options.

  2. In the bottom-left corner of the Options dialog, check the box that says, "Show all settings".

  3. In the tree-view on the left hand side, select "Projects and Solutions".

  4. In the options on the right, check the box that says, "Show advanced build configurations."

  5. Click OK.

  6. Go to Build -> Configuration Manager...

  7. In the Platform column next to your project, click the combobox and select "".

  8. In the "New platform" setting, choose "x86".

  9. Click OK.

  10. Click Close

July 20, 2011, Dirk Bondy says:

Thank you!!! This has been driving me insane for two days. You solved it.

August 16, 2011, nidheesh says:

We developed one windows application using VS 2005 with framework 2.0. This application is running perfectly on 32 bit Operating System. Now we need to give support for 64 bit OS.



While working with 64 bit Operating System we are getting the below error message.



"Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))".



Following is the code block



System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Driver));

this.axDriver = new AxCCNAccess.AxDriver();

((System.ComponentModel.ISupportInitialize)(axDriver)).BeginInit();

SuspendLayout();

//

// axDriver

//

axDriver .Enabled = true;

axDriver .Location = new System.Drawing.Point(241, 211);

axDriver .Name = "axDriver ";

axDriver .OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axDriver .OcxState")));

axDriver .Size = new System.Drawing.Size(41, 42);

axDriver .TabIndex = 0;

//

// Driver

//

AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

ClientSize = new System.Drawing.Size(292, 266);

Controls.Add(axDriver );

Name = "DriverContainer";

Text = "DriverContainer";

try

{

((System.ComponentModel.ISupportInitialize)(axDriver )).EndInit();

}

catch (Exception ex)

{

string sss = ex.Message;

}

ResumeLayout(false);



Getting issue in the try block.



Please help

i tried changing the compile options. but didnt worked out for me


Regards,

Nidheesh

August 31, 2011, Oscar P says:

It worked for me. I was compiling in a Win 7 64 and the .exe was not working on other PCs, but not anymore. THANKS.

September 1, 2011, Jose Luis Torres C says:

Thanks a lot!!!!, you save my life with this problem, I spent a lot of time trying to figureout!!!!.

September 8, 2011, your fan says:

Many many thanks! you are god!

October 11, 2011, majesty says:

it work... thank's...

October 13, 2011, DerekCoder says:

Thanks for the great info. You just saved me some valuable time.

November 19, 2011, Alireza says:

Really thanks
I was going to reinstall whole system , but now it is solved

December 2, 2011, Kai says:

Thank you,
now I can start enjoying my weekend.

December 8, 2011, VJ says:

Theo gray. Thanks a tonne. You saved a hell of a time.
Cheers.

December 11, 2011, Filip Z. says:

YOU ARE A GOD !!!!!!!!
You have no idea how many days I spent trapping errors, reading blogs, taking suggestions, trying almost everything possible anyone ever suggested, only your solution worked for me !!!

December 16, 2011, Roby says:

Thanks to all!!

January 13, 2012, Prasad says:

My development environment is XP32bit & client is tested on win764bit. Though i have created installer with the Release-X86 option, client is getting the AXHOST issue. please advice

January 13, 2012, Theo Gray says:

@Prasad The error is caused by the ActiveX control registration information not being found, so in the case of an x64 app, this is because the registration info is x86 based. In your case, have you checked that the ActiveX control is definitely registered on the client machine?


Comment on This Article:

Your Name:
Your Email Address:
 

Your Email Address will not be made public.
Comment:
All HTML, except <i>, <b>, <u> will require your comment to be moderated before it is publicly displayed.
 
If you would like your own avatar displayed, read about comment avatars.