3

I have two dll's (sqlite) , one dll is a 64 bit and other 32 bit dll. Is it possible to add reference dynamically based on processor architecture? P/Invoke is my last option. Any help would be appreciated!!

Sample Code:

string pathToDll = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\x64\\System.Data.SQLite.dll";
Assembly assembly = Assembly.LoadFrom(pathToDll);
AppDomain.CurrentDomain.Load(assembly.GetName());
Aster Veigas
  • 866
  • 3
  • 13
  • 34
  • 2
    possible duplicate of [Conditionally use 32/64 bit reference when building in Visual Studio](http://stackoverflow.com/questions/3832552/conditionally-use-32-64-bit-reference-when-building-in-visual-studio) – CodeCaster Oct 16 '13 at 08:42
  • Maybe it`s help to you. http://stackoverflow.com/questions/3832552/conditionally-use-32-64-bit-reference-when-building-in-visual-studio/3833444#3833444 – progpow Oct 16 '13 at 08:47
  • One may want to compile to Any architecture and run on both 32/64. Of course you can solve this by good installer, but this may not be a duplicate – wiero Oct 16 '13 at 08:49

1 Answers1

6

Yes, you can load assembly from a file

 Assembly.LoadFrom("MyAssembly.dll");

from .net4 you may use Is64BitOperatingSystem Environment property. Otherwise check IntPtr.Size which changes according to running architecture

Cannot encrypt / decrypt SQLite database in .NET4

Community
  • 1
  • 1
wiero
  • 2,176
  • 1
  • 19
  • 28