Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>UPDATE:</strong></p> <p>A technically unsupported but working solution is to p/Invoke LoadLibrary and specifically load the correct DLL early in the process. All managed and p/Invoke'd libraries are loaded "as needed". The CLR will load them for you when you invoke a method that depends on one of the types in that assembly (note: this is the "unsupported" part; this is <em>not</em> documented and may change in a future CLR version).</p> <p>The approach works because if an assembly is loaded via <code>LoadLibrary</code>, it's "found" by the CLR loader and the runtime will not attempt to load it again. We used this trick on CF to pre-load assemblies before doing much memory allocation to avoid out-of-memory situations.</p> <p>So, you should be able to do:</p> <pre><code>public static void Main() { LoadCorrectDLLs(); // .NET will ensure DotNetZip is loaded at this point. MethodInThisAssembly(); } public static void MethodInThisAssembly() { // Since MethodInThisAssembly uses DotNetZip, // its assembly will get loaded immediately before this method is called. IDotNetZipInterface x = null; ... } public static void LoadCorrectDLLs() { // p/Invoke LoadLibrary to load the correct version of DotNetZip. } </code></pre> <p>Note that the following will <em>not</em> work:</p> <pre><code>public static void Main() { LoadCorrectDLLs(); // This line would force DotNetZip to get loaded before Main() is called IDotNetZipInterface x = null; } </code></pre> <p><strong>Old answer; works on desktop framework only:</strong></p> <p>One trick is to place them in directories that won't be found during DLL loading (e.g., different subdirectories of your executable's directory) and handle <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx" rel="nofollow noreferrer">AppDomain.AssemblyResove</a>. David Morton has a decent write-up <a href="http://blog.codinglight.com/2009/07/assembly-resolution-with.html" rel="nofollow noreferrer">on his blog</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload