AppDomain.Unload issue
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);
}
}
pr开发者_如何学编程ivate static void Execute()
{
object key = new object();
Load(key);
Unload(key);
Load(key);
MyObject myobj= LoadedDomains[key].CreateInstance("asName", "type");
}
It sounds like you're describing a multi-threading problem, not a garbage collection problem - as in your code is trying to access the domain after it's been unloaded, but before the new one has been created and been assigned to the variable.
Unload synchronously unloads the AppDomain in question and will throw an exception if the domain cannot be unloaded.
Need more code to assist further...
I found the problem its in my code. Unloading the domain and not refreshing the dictionary.
精彩评论