Bewerken

Share via


ResolveEventArgs.RequestingAssembly Property

Definition

Gets the assembly whose dependency is being resolved.

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

Property Value

The assembly that requested the item specified by the Name property.

Remarks

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.

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. 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. 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. 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.

The semantics of the RequestingAssembly property vary, depending on how the requesting assembly was loaded:

  • Load 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. 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.

  • 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.

Applies to

See also