ResolveEventArgs.RequestingAssembly ResolveEventArgs.RequestingAssembly ResolveEventArgs.RequestingAssembly ResolveEventArgs.RequestingAssembly Property

定义

获取正在解析其依赖项的程序集。Gets the assembly whose dependency is being resolved.

public:
 property System::Reflection::Assembly ^ RequestingAssembly { System::Reflection::Assembly ^ get(); };
public System.Reflection.Assembly RequestingAssembly { get; }
member this.RequestingAssembly : System.Reflection.Assembly
Public ReadOnly Property RequestingAssembly As Assembly

属性值

请求了 Name 属性指定的项的程序集。The assembly that requested the item specified by the Name property.

注解

此属性返回的程序集是无法解析指定的项的程序集Name属性,因为项不存在该程序集中,在任何加载依赖项,或任何依赖项加载程序无法找到通过探测。The assembly that is returned by this property is an assembly that was unable to resolve the item specified by the Name property, because the item did not exist in that assembly, in any of its loaded dependencies, or in any dependencies the loader could find through probing.

例如,假定当前程序集使用Assembly.LoadFile方法以从位于探测路径外部目录才能使用 CA 类加载程序集 A。For example, suppose the current assembly uses the Assembly.LoadFile method to load assembly A from a directory outside the probing path, in order to use class CA. 假设进一步该类 CA 使用类 CB,在程序集 B 和程序集 A 具有对程序集 B 的编译时引用也位于探测路径外部。Suppose further that class CA uses class CB, in assembly B, and that assembly A has a compile-time reference to assembly B, also located outside the probing path. 如果当前程序集尝试实例化 CA,加载程序会尝试解析对程序集 B.的引用但是,因为使用加载程序集 AAssembly.LoadFile方法中,加载程序无法解析依赖项。When the current assembly attempts to instantiate CA, the loader attempts to resolve the reference to assembly B. However, because assembly A was loaded by using the Assembly.LoadFile method, the loader cannot resolve the dependency. 如果处理程序AppDomain.AssemblyResolve引发事件,该事件时,并RequestingAssembly生成的属性ResolveEventArgs对象包含程序集 A,因为程序集 A 是其程序集的缺少依赖关系。If there is a handler for the AppDomain.AssemblyResolve event, the event is raised, and the RequestingAssembly property of the resulting ResolveEventArgs object contains assembly A, because assembly A is the assembly that is missing a dependency.

语义RequestingAssembly属性有所不同,具体取决于请求的程序集的加载方式:The semantics of the RequestingAssembly property vary, depending on how the requesting assembly was loaded:

  • 加载上下文:该属性的值可能为nullLoad context: The value of the property might be null. 加载上下文是独立于加载顺序和的请求标识程序集不一定有意义。The load context is load-order independent, and the identity of the requesting assembly is not necessarily meaningful. 非 null 示例发生时Type.GetType调用方法和指定的类型不知道请求的程序集或其任何依赖关系。A non-null example occurs when the Type.GetType method is called and the specified type is not known to the requesting assembly or any of its dependencies.

  • 加载位置上下文:该属性可用作一个探测的提示,但事件处理程序应获取给定的程序集名称的多个请求。Load-from context: The property can be used as a probing hint, but the event handler should not get more than one request for a given assembly name.

  • 没有上下文 (即,请求的程序集加载使用Assembly.LoadFile方法,或作为字节流,或在混合模式下):该处理程序可以使用RequestingAssembly属性以加载同一程序集的不同实现基于请求的程序集的标识。No context (that is, the requesting assembly was loaded by using the Assembly.LoadFile method, or as a byte stream, or in mixed mode): The handler can use the RequestingAssembly property to load different implementations of the same assembly based on the identity of the requesting assembly.

适用于

另请参阅