Loading the same Assembly twice but with different version
<p>I have one assembly that is called asm.dll.</p>

<p>This assembly has the version 1.0.0.0 (<em>set within AssemblyInfo.cs</em>)</p>

<p>Then I need do do some code modifications in that assembly (still asm.dll), advance the version to 2.0.0.0 and build it again.</p>

<p>Now, I have two files named asm.dll that differ with respect to some code modifications and a their version number.</p>

<p>How do I load these two files during runtime?</p>

<p><strong>ADDENDUM:</strong></p>

<p>Right now I am trying the following:</p>

<pre><code>var asm1 = Assembly.LoadFrom("dir1\asm.dll");
var asm2 = Assembly.LoadFrom("dir2\asm.dll");

var types1 = asm1.GetTypes();
var types2 = asm2.GetTypes();

Type type1 = types1.First&lt;Type&gt;(t =&gt; t.Name.Equals("myClassIWantToInstantiate"));
Type type2 = types2.First&lt;Type&gt;(t =&gt; t.Name.Equals("myClassIWantToInstantiate"));

MyObject myObject1 = (MyObject1)Activator.CreateInstance(type, new object[] { });
MyObject myObject2 = (MyObject2)Activator.CreateInstance(type, new object[] { });
</code></pre>

<p>But I get the following behavior:</p>

<ul>
<li><p>the first call to <code>Activator.CreateInstance(...)</code> correctly returns the requested instance for <code>myObject1</code></p></li>
<li><p>the second call to <code>Activator.CreateInstance(...)</code> returns again <code>myObject1</code> instead of <code>myObject2</code></p></li>
<li><p>The code compiles and the program runs without exception or observable problems, except that I do not get <code>myObject2</code></p></li>
</ul>

<p>I am aware of <a href="https://stackoverflow.com/questions/2016990/net-load-two-version-of-the-same-dll/2023445#2023445">this answer</a> and I think the code I used, is the same, only a bit newer (correct me, if I am wrong).</p>