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

PingPhotonics
PingPhotonics used Ask the Experts™
on
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?

Thanks
activeX-error.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Janusz CzopowikSenior Software Engineer

Commented:
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?

Author

Commented:
Hi John
Yes I have no problem rebuilding my ActiveX
Janusz CzopowikSenior Software Engineer

Commented:
Does problem persist after rebuilding?
Hi

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)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial