Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Reflection, AppDomain: Execute same assembly from different folders
    text
    copied!<p>I have the following situation. There are n folders, each containing two assemblies:</p> <p><strong>Assembly1.dll</strong> and <strong>Assembly2.dll</strong></p> <ul> <li><p>All Assembly1.dll's are exactly the same</p></li> <li><p>All the Assembly2.dll's are slightly different from each other, but have the same classes/methods.</p></li> <li><p>All Assembly1.dll's reference to Assembly2.dll </p></li> </ul> <p>In my program, I would like to create an instance of some class inside Assembly1 and call a method on that class:</p> <pre><code>for(int i = 0; i &lt; 100; i++) { Assembly myAssembly1 = Assembly.LoadFrom("Directory"+ i + "\\Assembly1.dll"); Type myType = myAssembly1.GetType("MyClass"); object myObject = Activator.CreateInstance(myType); myType.Invoke(myMethodName, BindingFlags.InvokeMethod, null, myObject, null); } </code></pre> <p>This piece of code gets executed for each folder containing an Assembly1.dll The problem is that the first one works fine but afterwards the Assembly2.dll has already been loaded and will not be reloaded. However, it needs to be replaced by the one which is inside the current folder (number i). This is because it is slightly different. </p> <p>At the moment each time I call the above piece of code, the same assembly2 will be taken. </p> <p>I have already searched for similar questions and I found some suggestions about using custom <strong>AppDomains</strong>. I tried this, but I could not get it to work properly.</p> <p>Could someone give a code example of how to initialize a new AppDomain and execute the above mentioned code inside this new domain (so that the referenced Assembly2.dll will be loaded and unloaded correctly)?</p> <p>Or does anyone have a different idea of how to solve that problem?</p> <p>Best wishes, Christian</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