0

I am using a 3rd party library that provides separate x86 and x64 assemblies (with the same API). I want to compile my main executable once as AnyCPU, and let the loader select the correct version of the library to load at runtime. Is this possible?

I am aware that there is a way to automatically select the correct version at compile-time. However, this means I have to distribute two versions of my executable, which I don't want.

What I do not want:

MyApp64/
  MyApp64.exe
  Library64.dll
MyApp32/
  MyApp32.exe
  Library32.dll

What I do want:

MyApp/
  MyApp.exe (AnyCPU)
  Library32.dll  <-- loaded on 32-bit OS
  Library64.dll  <-- loaded on 64-bit OS
Andrew Sun
  • 4,101
  • 6
  • 36
  • 53
  • There are some similar questions on StackOverflow, You can find them simply search on Google. – DDoSolitary Jul 25 '16 at 07:23
  • @Stalker I was only able to find info on building for both x86 and x64 **separately**. If you can find an answer for *my* problem, please do share it, because I certainly haven't been able to :-) – Andrew Sun Jul 25 '16 at 07:36
  • Oh sorry, I just didn't read what I find on Google carefully. I think there is no direct solution to your situation. So what kind of DLL are you trying to load? Native or managed. Tell me then I can give you a workaround. – DDoSolitary Jul 25 '16 at 07:39
  • @Stalker It's a managed assembly. – Andrew Sun Jul 25 '16 at 07:43
  • 1
    You can visit this [link](http://stackoverflow.com/questions/108971/using-side-by-side-assemblies-to-load-the-x64-or-x32-version-of-a-dll) to see a workaround that uses a custom assembly resolver. – DDoSolitary Jul 25 '16 at 07:50
  • Or you can just create a wrapper class that uses reflection to load the DLL dynamically and call the methods in the DLL. – DDoSolitary Jul 25 '16 at 07:52
  • @Stalker Ah, I didn't see that. I guess a hacky solution is the only way to go, then? I was hoping there was official support for this in .NET. – Andrew Sun Jul 25 '16 at 08:23
  • I think if there is official support for this, it can be easily found in any search engine, but I can't. – DDoSolitary Jul 25 '16 at 09:03

0 Answers0