Adding references dynamically in .NET

2019-04-11 01:30发布

问题:

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());

回答1:

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



标签: c# .net dll