I have following requirement,
I don't want to keep it in the directory where the Executable(.exe) is kept.
How can i keep the 'System.Data.Sqlite.dll' file at some other directory , and load it safely at runtime, before its getting referenced in application code ?
you can use manual assembly resolution to do this.
You need to provide a delegate to the AssemblyResolve event in the current AppDomain
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += assemblyResolver.ResolveEventHandler;
when the application has any assembly references that it can't resolve it will call this delegate to get the assembly resolved. You can then simply return the assembly requested from the delegate:
Assembly assembly = Assembly.LoadFrom (assemblyPath);
return assembly;
hope this helps
I'm not sure why you want to do this again, it's a deviation from the best practices, But to answer your question: You could use
Assembly.LoadFrom Method (String path)
From the System.Reflection
Namespace
& having the path in the app.config file
Assembly.LoadFrom on MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With