J
Jon Shemitz
I am responsible for the plugin-loading part of an app. One of the
things the loader has to do is check licensing, and unload any
unlicensed plugins.
I naively did this as:
AppDomain Sandbox = AppDomain.CreateDomain("Sandbox");
try
{
Assembly Suspect = Sandbox.Load(PluginName);
// do some tests on Suspect.GetExportedTypes()
}
finally
{
AppDomain.Unload(Sandbox);
}
The code seemed to work, but it turns out that
Sandbox.Load(PluginName) is actually loading the PluginName into both
the Sandbox AppDomain and the default AppDomain. When I unload
Sandbox, I'm left with all tested plugins still loaded into the
default AppDomain, whether they are licensed or not.
I do NOT want to execute any assemblies: I just want to load my
suspects; do some tests in the temp AppDomain; and return the test
results to the default AppDomain.
It looks like my only option is to use AppDomain.DoCallBack to execute
my tests, and use SetData to store the results. Is there a better way?
things the loader has to do is check licensing, and unload any
unlicensed plugins.
I naively did this as:
AppDomain Sandbox = AppDomain.CreateDomain("Sandbox");
try
{
Assembly Suspect = Sandbox.Load(PluginName);
// do some tests on Suspect.GetExportedTypes()
}
finally
{
AppDomain.Unload(Sandbox);
}
The code seemed to work, but it turns out that
Sandbox.Load(PluginName) is actually loading the PluginName into both
the Sandbox AppDomain and the default AppDomain. When I unload
Sandbox, I'm left with all tested plugins still loaded into the
default AppDomain, whether they are licensed or not.
I do NOT want to execute any assemblies: I just want to load my
suspects; do some tests in the temp AppDomain; and return the test
results to the default AppDomain.
It looks like my only option is to use AppDomain.DoCallBack to execute
my tests, and use SetData to store the results. Is there a better way?