嗨,我正在将 dll 加载到另一个域中,加载到该域时它工作正常,但是当我想通过代理对象从该域获取一些信息时,它给了我异常下面是审查代码是否有任何错误步骤?
public class AssemblyProxy
{
System.Type[] _types;
public System.Type[] GetTypes()
{
return _types;
}
public string FullName { get; set; }
public void LoadAssembly(string path)
{
try
{
Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
AppDomain TestDomain = AppDomain.CreateDomain("AssemblyDomain", evidence, AppDomain.CurrentDomain.BaseDirectory, System.IO.Path.GetFullPath(path), true);
Proxy _asmProxy = (Proxy)TestDomain.CreateInstanceFromAndUnwrap(AppDomain.CurrentDomain.BaseDirectory+"Common.dll", typeof(Proxy).FullName);
_asmProxy.LoadAssembly(path);
FullName = _asmProxy.FullName;
_types = _asmProxy.GetTypes(); //Here i got Exception [Can not load file or assembly]
AppDomain.Unload(TestDomain);
}
catch (Exception ex)
{
}
}
}
class Proxy : MarshalByRefObject
{
System.Type[] _types;
public string FullName { get; set; }
public System.Type[] GetTypes()
{
return _types;
}
public void LoadAssembly(string path)
{
System.Reflection.Assembly _assembly = System.Reflection.Assembly.Load(System.IO.File.ReadAllBytes(path));
_types = _assembly.GetTypes();
FullName = _assembly.FullName;
}
}
我得到的例外是:
无法加载文件或程序集