Pygmy's picture

VS2010 X64 : WPF - Can't open designer-view using GLControl

I'm using an OpenGL-control in my WPF-app.
Works fine in x86, but when I switch to x64 I get a designer-error saying

<b>System.BadImageFormatException</b>
Could not load file or assembly 'OpenTK.GLControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4' or one of its dependencies. An attempt was made to load a program with an incorrect format.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)

which looks like in x64 when switching to designer-view it still wants to load an x86 assembly.
All my projects are configured for x64 though.

I can switch back to x86, do my UI-design there and then switch back to x64 and compile and run, but it's a bit cumbersome so I prefer to fix it if possible :)

Anyone seen this before ?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
haplokuon's picture

You can choose in the application properties window Build->Platform target->Any CPU, and let the Just In Time Compiller decide according to the machine where your application is running.

The BadImageFormatException appears when you try to mix x86 and x64 compiled code. I checked the configuration for OpenTK and is AnyCPU.

You can always try to compile OpenTK and specify the platform target as x64.

Pygmy's picture

I'm already compiling OpenTK (and all my other projects) as x64.

haplokuon's picture

What it might be happening is that during compiling time your application is pointing at the OpenTK.Control.dll that you compiled as x64 library, the one specified in the references. But during design time, the UI desiger is pointing to a different OpenTK.Control.dll library.

If you have inserted the opentk control dragging and dropping from the tool box, check which library it is pointing to, maybe you have several copies of the OpenTK.Control.dll in your system.

Pygmy's picture

The GLControl is hosted in a winforms-host.
On design-time Visual Studio seems to figure out what dll to use using reflection, and then seems to want to load the wrong dll.
No clue on how to make sure VS loads the x64 dll at design-time.