2
votes

I'm working in Visual Studio 2010 Ultimate, and I'm having issues with adding certain controls to my Windows Form. I've got two projects, PeakEstimator and PeakEstimatorUI in the same solution. PeakEstimatorUI (my GUI) depends on PeakEstimator (my back end) and everything compiles and runs as expected with the Form and controls I have presently.

I'm running into an issue now however, when I try to add certain controls. TextBoxes, Buttons, Labels, OpenFileDialog controls, and lots of other things work fine, but when I try to add a Chart, LineShape, OvalShape, ReportViewer, ElementHost, etc., I get the following error:

Failed to create component 'component name'. The error message follows: 'System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

I've been searching for similar problems, and most threads I've seen talk about x86 vs x64 issues, but I was under the impression that using clr would handle those things for me. Perhaps I've got a fundamental misunderstanding there.

All the controls I'm having trouble with seem to work fine if I create a new Windows Form project, so I assume it must have something to do with the configuration of my project(s). Any ideas?

This is the first time I've developed any sort of serious GUI or used Visual Studio, and it's the first time I've programmed in Windows in a long time, so please, explain it like I'm 5.

Thanks for your time,

Dave

2

2 Answers

1
votes

Usually this is an error when you try to load a 32 bit DLL into a 64 bit application. Is that possible in your environment?

If you have an external dependency and just have the .DLL file, you can use the Visual Studio Command Prompt to see if it's 32 bit or not: corflags myReference.dll. You're looking for the 32BIT flag. If it's something you have control over, check the project/solution to make sure it's set to build for AnyCPU and not x86 (note: x86 may be required if it does COM interop or uses another 32-bit assembly).

If you're on a 64 bit machine and have a solution that's set to AnyCPU build configuration and try to subsequently load a 32 bit assembly, this exception will be thrown. You can change your solution to build for x86 and that should solve the problem.

Some more resources:

0
votes

Sorry, my initial answer was for C#.

For C++ you'll want to look at /CLRIMAGETYPE. here's the MSDN that explains how it works and where to set it in VS2010:

http://msdn.microsoft.com/en-us/library/31zwwc39(v=vs.100).aspx

And here's a screenshot of the properties page. I'm not sure which value to change to, but you can experiment to see what works for you.

enter image description here