Is appdomain unloads at time when I call AppDomain.Unload(name) method. Or it flags for the next garbage collection. I have following situation Collection of AppDomains. ListApp Unload the particular domain say d1 from ListApp Immediately after unloading d1 again create domain d1 and add it in ListApp When I use d1.CreateInstanceAndUnwrap() method it throws exception "attempted to access an unloaded appdomain"
public static IDictionary<object, AppDomain> LoadedDomains { get; internal set; }
private static void Load(object key)
{
if (!LoadedDomains.Contains(key))
{
AppDomain domain = AppDomain.CreateDomain("t");
LoadedDomains.Add(key, domain);
}
}
private static void UnLoad(object key)
{
if (LoadedDomains.Contains(key))
{
AppDomain.Unload(LoadedDomains(key));
LoadedDomains.Remove(key);
}
}
private static void Execute()
{
object key = new object();
Load(key);
Unload(key);
Load(key);
MyObject myobj= LoadedDomains[key].CreateInstance("asName", "type");
}
string
keys, but you useobject
as the keys in your methods. – Mike Two