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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

5 Comments

How will I use the dll methods,since I will be dynamically adding reference?
I added a link to my other response which should help you
I read about the assembly.loadfrom method. It looks like the real deal, I'll confirm the solution tomorrow
I tried assembly.loadfrom method. It gets loaded but VS still throws exception. It still thinks that the file is x86 (on x64 machine)
A quick question, can I fake the System.Data.SQLite namespace to the compiler?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.