Hot Unload/Reload of a DLL used by an Application
<p>I have an application that loads a DLL to execute a specific part of processing</p>

<pre><code>Example : "Application.dll" loading "Process.dll" 
</code></pre>

<p><strong>Process.dll is dynamically loaded at Runtime</strong>, using reflection, and not referenced in the application.</p>

<p>After processing is finished, the dll needs to be recompiled on server and loaded back again later.
<br>In order to do so, I need to free it, otherwise I get the following message :
"Unable to copy file "Process.dll" to "Process.dll". The process cannot access the file 'Process.dll' because it is being used by another process."</p>

<p>So the question is : How to programatically free/release/unload the Process.dll from my application before loading it back again. Of course the whole point is to do this <strong>WHITHOUT</strong> stopping the Application.</p>

<p><strong>EDIT 1 :</strong> </p>

<p>A proposed solution goes like this : </p>

<pre><code>AppDomain newDomain4Process = AppDomain.CreateDomain("newDomain4Process");
Assembly processLibrary = newDomain4Process.Load("Process.dll");
AppDomain.Unload(newDomain4Process);
</code></pre>

<p><strong>The problem I am still having</strong> is that though I am giving the proper full path, I get a file not found Exception. The answer to <a href="http://stackoverflow.com/questions/2132649/loading-unloading-assembly-in-different-appdomain">this post</a> did not have the expected effect either.</p>

<p><strong>EDIT 2 :</strong> </p>

<p><a href="http://stackoverflow.com/questions/658498/how-to-load-assembly-to-appdomain-with-all-references-recursively">this post</a> saved my life, here is the code :</p>

<pre><code>class ProxyDomain : MarshalByRefObject
    {
        public Assembly GetAssembly(string AssemblyPath)
        {
            try
            {
                return Assembly.LoadFrom(AssemblyPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

   ProxyDomain pd = new ProxyDomain();
   Assembly a = pd.GetAssembly(FullDLLPath);
</code></pre>

<p><strong>EDIT 3 :</strong> <br>
Did't get to acces the AppDOmain and unload it with The previous Solution though.
When I used the classic method of AppDomain Creation, I felt into Alexei's warning : AppDomain.Unload "seemed" to work, but the Assembly was still loaded (Module View).
So I still have my problem in some way, since I can't really unload the DLL efficiently.</p>
