1

I am using an external dll in my project. When i try to run the application on a 64bit machine, it crashes with a FileLoadException. Since it works fine on a 32bit system, i suspect the dll to be 32bit. However, setting the project's target platform to x68 doesn't help.

I read 32bit dll in 64bit application in c# and Load 32bit DLL library in 64bit application and some other pages that tell i should build the whole app as a 32bit process (which wouldn't bother me - it should just be executable on a 64bit windows), but i don't know how to build a 32bit app on a 64bit dev machine if not by setting the target platform...

The code is just

static void Main(string[] args)
{
    var mf = new QuickFix43.MessageFactory();
    Console.WriteLine("running");
    Console.ReadKey();
}

and the QuickFix stuff is from the dll.

Edit: I checked the dll with CorFlags and figured

CLR Header: 2.5
PE        : PE32
CorFlags  : 16

which means that the dll is a Mixed-mode assembly that can be loaded only in an i386 environment ( http://blogs.msdn.com/b/slessard/archive/2010/04/09/types-of-managed-code-assemblies.aspx )

Is is it possible to load this in an 64bit environment?

Community
  • 1
  • 1
Martin Booka Weser
  • 3,192
  • 5
  • 28
  • 41
  • Possible duplicate to: http://stackoverflow.com/questions/5478904/32bit-dll-in-64bit-application-in-c – BitKFu Apr 28 '11 at 07:36
  • People put effort into helping you by answering your question. Deleting this would result in them losing reputation. If your issue is solved by some other means, leave an answer with your solution and select it when the option to do so becomes available. This helps people who have similar issues and does not penalize those that tried to help you. –  Apr 28 '11 at 13:37

2 Answers2

2

You can also run 32bit applications on an 64bit environment. But if you want to load a 32bit DLL you must build your application as a 32bit one. You can do this by setting the target platform to x86 in the "Debug" and "Release" mode. This should solve your problem.

Aykut Çevik
  • 2,060
  • 3
  • 20
  • 27
0

OK, so heres the answer. The problem was actually not that my project could not load the native dll. The problem was that my project calls a managed dll that calls the native dll in question. The target platform of my project was set to x68 but the managed dll was compiled as "any cpu". Recompiling the intermediate managed dll with x68 worked.

Martin Booka Weser
  • 3,192
  • 5
  • 28
  • 41