I have the following class (shortened for easiness of reading)
public class Connection
{
Guid _id;
AppDomain _appDomain;
Type _coreApp;
public string ConnectionName
{
get
{
this._coreApp.InvokeMember("_some_property_", BindingFlags.GetProperty, null, null, null).ToString();
}
}
public Connection(string username, string password)
{
this._id = Guid.NewGuid();
this._appDomain = AppDomain.CreateDomain(this._id.ToString());
Assembly asm = this._appDomain.Load("_some_dll_");
this._coreApp = asm.GetExportedTypes().First(t => t.Name == "_some_type_");
this._coreApp.InvokeMember("_some_method_", BindingFlags.InvokeMethod, null, null, new object[] { username, password });
}
}
I also have the following code
public class Main()
{
public Main()
{
Connection connOne = new Connection("_some_user_1_", "_some_pw_1_");
Connection connTwo = new Connection("_some_user_2_", "_some_pw_2_");
string nameOne = connOne.ConnectionName;
string nameTwo = connTwo.ConnectionName;
}
}
I also got these facts:
- The dll I'm loading into the AppDomain is a 3rd party
- _some_method_ and _some_property_ are static
- ConnectionName should return different values for both instances as the parameters aren't the same.
And last I got this issue:
I was working under the assumption that calling a static method from a Type within a DLL in its own AppDomain, would isolate that call from others to the same static method in the same DLL in a separate AppDomain, but for some reason this isn't the case. If I run the code like that I would, for example, get both strings as "result_1", inverting the parameters would set both strings to "result_2".
I basically need to totally isolate the dlls on each instance of Connection as there are a lot of static things going on and I can't have one changing the other, as is the case.
I'm not sure that code even compiles, please ignore any grammar or semantic issue as I can't post the actual code and had to write this on the fly and on the browser.