如何使用AppDomain.CreateDomain与AssemblyResolve?
我想从使用WCF内存加载我的程序集。每一件事情是工作好当的:
i want to load My Assemblies from wcf by using Memory. Every thing is working good WHEN:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
Assembly[] assBefore = AppDomain.CurrentDomain.GetAssemblies();
foreach (byte[] binary in deCompressBinaries)
loadedAssembly = AppDomain.CurrentDomain.Load(binary);
但我想用AppDomain.CreateDomain不是当前域:
but i want to use AppDomain.CreateDomain not current domain:
protected void LoadApplication()
{
this.ApplicationHost = AppDomain.CreateDomain("TestService", null, new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
});
ApplicationHost.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve);
foreach (AssemblyName asmbly in System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
ApplicationHost.Load(asmbly);
}
List<byte[]> deCompressBinaries = new List<byte[]>();
foreach (var item in AppPackage.Item.AssemblyPackage)
deCompressBinaries.Add(item.Buffer);
var decompressvalues = DeCompress(deCompressBinaries);
deCompressBinaries.Clear();
deCompressBinaries = decompressvalues.ToList();
foreach (byte[] binary in deCompressBinaries)
ApplicationHost.Load(binary);
Assembly[] assAfter = AppDomain.CurrentDomain.GetAssemblies();
}
Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
return Assembly.Load(args.Name);
}
我有2个ClassLibraries。 ClassLibrary1的和ClassLibrary2使用如下:
i have 2 ClassLibraries. ClassLibrary1 and ClassLibrary2 using below:
namespace ClassLibrary2
{
public class Class1 : MarshalByRefObject
{
public Class1()
{
}
public int GetSum(int a , int b)
{
try
{
ClassLibrary1.Class1 ctx = new ClassLibrary1.Class1();
return ctx.Sum(a, b);
}
catch
{
return -1;
}
}
public int GetMultiply(int a, int b)
{
return a * b;
}
}
}
Classlibrary2取决于ClassLibrary1的。所以,我使用assemblyresolver。但是,在错误的 ApplicationHost.Load(二进制);
错误:无法加载文件或程序集ClassLibrary1的,版本为1.0。 0.0,文化=中性公钥= null或它的一个依赖。该系统找不到指定的文件。
也没有发射ASSEMBLYRESOLVER。纽约光标不布莱恩Assemblyresolver方法。如何与解决方法使用AppDomain.CreateDomain?
Also NOT FIRING ASSEMBLYRESOLVER. ny cursor is not goin to Assemblyresolver method. How to use AppDomain.CreateDomain with resolve method?
我个人不喜欢从字节数组装载组件。我觉得这是更好地程序集保存到临时文件夹,然后从文件夹中加载它们。看看这篇文章:应用程序域是很难...
I personally dont like loading assemblies from byte array. I think it is better to save your assemblies to temp folder and then load them from that folder. Take a look at this article: Application Domains is hard…