title: Replacing a DLL on a Windows shared folder that is used by a C# .NET application
body: <p>We have an enterprise management software that our clients deploy to a Windows network shared folder that several users from several terminal servers launch our program from.</p>
  <p>What we're trying to achieve is a way to replace a DLL while the program is being used by the users to apply patches to fix bugs. At the moment weirdly enough, we are able to rename the old DLL to replace and apply the new one without any errors regarding the file being used.</p>
  <p>This causes us two problems though:</p>
  <ul>
  <li>the new DLL isn't loaded by the application if an instance of the same application is still using the old DLL (I think this is a case of <a href="https://en.wikipedia.org/wiki/DLL_Hell#Shared_in-memory_modules" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/DLL_Hell#Shared_in-memory_modules</a>)</li>
  <li>Exceptions are thrown left and right by applications that were run before the replacing because they were only loaded partially (lazy loading) and the when its time to go look into the file for the parts that are missing that are being requested the IL code doesn't match what's in memory anymore.</li>
  </ul>
  <p>The bottom line of this is I think that we're doing something we are not supposed to: renaming something that is being used.</p>
  <p>The possible solutions I found so far are two:</p>
  <ul>
  <li>launch the application with a new AppDomain with shadow copying enabled, but this is not reliable as every client has its own environment and we might get unexpected permission errors or something of this nature</li>
  <li>load assemblies without locking them. On this note we've looked into using reflection (which we actually use to some extent) but we're unsure on how to load through reflection assemblies that are already referenced in the project by the DLL (we have multiple DLL referecing other DLL that are referencing other DLL, etc....).</li>
  </ul>
  <p>Do any of you have any other idea on how to overcome this problem safely? Or how to solve the last point I mentioned above with the reflection?</p>