title: C# Avoid file lock when Assembly.Load
body: <p>My situation is;</p>
  
  <p>I am designing a plugin application, based on dynamically loading plugin assemblies more than one user may run the application that's hosted on a server machine. Application is auto-updating plugin assemblies from my live update server on its startup. So plugin files (and its satellite dlls should not be locked on file system.</p>
  
  <pre><code> byte[] assemblyBytes = File.ReadAllBytes("asm-path");
   var assembly = Assembly.Load(assemblyBytes);
  </code></pre>
  
  <p>as expected not locking the dll file. but what if the dll I am loading has static reference dlls itself? they are locked on file system now.</p>
  
  <p>to name files, lets say;</p>
  
  <ul>
  <li>APP.Exe is my base application;</li>
  <li>PL1.dll is my first plugin, APP.exe loads it in a new Appdomain</li>
  <li>PL2.dll is my second plugin, APP.exe loads it in a new Appdomain</li>
  <li>PL1_S.dll is a static reference dll for PL1.dll plugin, loaded in PL1 AppDomain</li>
  <li>PL_COMMON is a static reference dll for both PL1 and PL2 plugins, loaded by PL1 and PL2 AppDomains</li>
  </ul>
  
  <p>PL1_S and PL_COMMON also should not be locked in file like PL1 and PL2 assemblies</p>
  
  <p>Any idea on how to solve that?</p>