C#.NET - Adding my ActiveX control to my Form throws an Exception

See the screenshot of the exception produced when I try and drag and drop my newly created and registered ActiveX control

My ActiveX control was originally written using Visual Studio 2003 for Windows XP (32-bit)
I used Visual Studio 2008 and recompiled it for 64-bit Windows. I set the platform to x64.
It compiled OK with no errors I then registered it OK from the command line (had to "Run as Administrator") using regsvr32.

I then added my ActiveX (*.ocx) control to by ToolBox. When I dragged my control onto my Windows form I  got the attached error (see the screenshot). The error starts off;

Failed to create component 'AxHost'. The error message follows: 'System .BadImageFormatException: A wrapper assembly is not registered for this type library. at System.Windows.Forms.Design.DocumentDesigner....

Any ideas whats happening here.  Anyone had a similar problem that they managed to fix?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Janusz CzopowikSenior Software EngineerCommented:
It seems like your ocx image is either corrupted or built using format that is not up to the standard of the CLR, or it is built as 64-bit image in 32 bit app or possible vice versa.
Are you able to rebuild your ActiveX?
PingPhotonicsAuthor Commented:
Hi John
Yes I have no problem rebuilding my ActiveX
Janusz CzopowikSenior Software EngineerCommented:
Does problem persist after rebuilding?
PingPhotonicsAuthor Commented:

I seem to have solved this. Well almost. What Ive done is compile the ActiveX as a Win32 application. Ive then added the control to the Visual Studio ToolBox (using choose Items...)

I've then created my application as any CPU platform. I now have no problem adding my ActiveX control to my application. My application runs on both 32-bit and 64-bit windows which is what I want.

So as long as I don't compile my ActiveX as a 64-bit there is no problem. It makes me wonder I want to compile anything as x64. Why not just set it to Any CPU?

Anyway thanks for your efforts. Not sure how to award points in this scenario (your first answer probably has some value)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.