I am trying to load an assembly into an application domain. I can successfully load the assembly into the current domain, but I need to load it into an application domain so that I can unload it. The code is as follows:
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\XXX\\XXX.dll";
AppDomain xxxDomain = AppDomain.CreateDomain("XXX Domain");
Type type = typeof(ProxyDomain);
ProxyDomain xxxInstance = (ProxyDomain)xxxDomain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
Assembly xxxAssembly = xxxInstance.GetAssembly(path);
However, when I call Load, I get the following error:
Could not load file or assembly XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
The ProxyDomain class is as follows:
class ProxyDomain : MarshalByRefObject
{
public Assembly GetAssembly(string path)
{
try
{
return Assembly.LoadFrom(path);
}
catch (Exception ex)
{
throw new InvalidOperationException("Failed to load assembly from path: " + path, ex);
}
}
}
Thank you in advance.