Search code examples
visual-studio-2012build64-bitfreeswitch

BadImageFormat exception at runtime


I am trying to build the FreeSWITCH .NET ESL client library, as per the instructions here on a 64-bit Windows 7 machine, with VS 2012 targeting .NET 4.5, and reference the built DLLs in my own project. The build of both libraries is successful, as is the build of my project.

However, when I try to run my project, I get a BadImageFormat exception on the following line:

var conn = new ESLconnection(socketClient.Handle.ToInt32());

which seems as though it's trying to use a 32-bit assembly.

This, even though I set the build configuration of both the main FreeSWITCH library project and the ESL project is Release / x64, and the build configuration of my project is set to Release / AnyCPU.

I tried setting my project to Release / x64, but that doesn't help. Nor does it help to add the projects as existing projects to my solution, instead of only referencing the built DLLs.

In any case, the sample project (ManagedESLTest.2012) which does work, has a build configuration of Release / AnyCPU, so that is not the problem.

How can I resolve this issue?


Solution

  • The Prefer 32-bit (project Properties -> Build) checkbox needs to be unchecked. The ManagedESLTest.2012 sample project worked because it was targeting .NET 4, which doesn't have this option.