[英]Load dll into another domain exception
Hi I am loading dll into another domain, it works fine when loaded into that domain but when i want some information from that domain through proxy object it gives me exception below is the code for review is there any wrong step ??? 嗨,我正在将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;
}
}
The exception I get is: 我得到的异常是:
Can not load file or assembly
无法加载文件或程序集
The way I solved this problem was by calling LoadFrom (not Load) and in the context of the AppDomain : 我解决此问题的方法是通过调用LoadFrom(而不是Load)并在AppDomain的上下文中进行 :
sDomain = AppDomain.CreateDomain(DOMAIN_NAME);
sDomain.DoCallBack(AppDomainCallback);
// runs in the context of the AppDomain
private void AppDomainCallback()
{
Assembly assembly = Assembly.LoadFrom(mAssemblyName);
}
I Have solved the issue by reading following Blog Post: the problem in my case is that i am returning System.Type Object from new domain which is no allowed you can return strings from proxy object but not System.Type object 我已经通过阅读以下博客文章解决了问题:在我的情况下,问题是我从新域返回System.Type对象,不允许从代理对象返回字符串,但不能从System.Type对象返回字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.