本文介绍了当 Assembly 在 CurrentDomain 中时,为什么会调用 AssemblyResolve?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一种情况,AppDomain.CurrentDomain.AssemblyResolve 被调用用于已使用 Assembly.Load(myAssemblyMemStream.ToArray())Assembly.Load(myAssemblyMemStream.ToArray()) 加载到当前域的程序集代码>.

I have a situation where AppDomain.CurrentDomain.AssemblyResolve is called for an assembly that has already been loaded into the current domain using Assembly.Load(myAssemblyMemStream.ToArray()).

这是为什么?

我需要执行以下操作才能使其正常工作.这与 .NET 自动执行的操作有何不同?

I need to do the following to get it to work. How does this differ from what .NET does automatically?

Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    return AppDomain.CurrentDomain
                    .GetAssemblies()
                    .First(x => x.FullName == args.Name);
}

推荐答案

加载上下文 http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx.加载 byte[] 不会导致其他加载上下文中的程序集能够看到它.这是一个安全功能.

Load contexts http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx. Loading the byte[] doesn't cause assemblies in other load contexts to be able to see it. It is a security feature.

这篇关于当 Assembly 在 CurrentDomain 中时,为什么会调用 AssemblyResolve?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 10:58