ResolveEventArgs.RequestingAssembly 属性

定义

获取正在解析其依赖项的程序集。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方法从探测路径外的目录加载程序集 A, 以便使用类 CA。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 在程序集 B 中使用类 CB, 并且该程序集 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 的引用。但是, 由于程序集 A 是通过使用Assembly.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事件的处理程序, 则引发事件, 并且生成ResolveEventArgs的对象RequestingAssembly的属性包含程序集 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. 如果Type.GetType调用方法, 并且指定的类型对请求程序集或其任何依赖项未知, 则会发生非 null 示例。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.

适用于

另请参阅