Assembly.Load Method (AssemblyName, Evidence)
Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence.
[Visual Basic] Overloads Public Shared Function Load( _ ByVal assemblyRef As AssemblyName, _ ByVal assemblySecurity As Evidence _ ) As Assembly [C#] public static Assembly Load( AssemblyName assemblyRef, Evidence assemblySecurity ); [C++] public: static Assembly* Load( AssemblyName* assemblyRef, Evidence* assemblySecurity ); [JScript] public static function Load( assemblyRef : AssemblyName, assemblySecurity : Evidence ) : Assembly;
- The AssemblyName object that describes the assembly to be loaded.
- Evidence for loading the assembly.
The loaded assembly.
|ArgumentNullException||assemblyRef is a null reference (Nothing in Visual Basic).|
|FileNotFoundException||assemblyRef is not found.|
|BadImageFormatException||assemblyFile is not a valid assembly.|
|FileLoadException||An assembly or module was loaded twice with two different evidences.|
|SecurityException||The caller does not have the required permission.|
The Load methods use the default load context, which records the assembly name and assembly instance information for the set of assemblies that is the transitive closure of the assemblies referenced by a managed application. The default load context applies to assemblies that are loaded with a Load method and that use a fully qualified assembly reference.
Whether certain permissions are granted or not granted to an assembly is based on evidence. The rules for assembly and security evidence merging are as follows:
- When you use a Load method with no Evidence parameter, the assembly is loaded with the evidence that the loader supplies.
- When you use a Load method with an Evidence parameter, pieces of evidence are merged. Pieces of evidence supplied as an argument to the Load method supersede pieces of evidence supplied by the loader.
- When you use a Load method with a Byte parameter to load a common object file format (COFF) image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.
- When you use a Load method with a Byte parameter and Evidence to load a common object file format (COFF) image, only the supplied evidence is used. Evidence of the calling assembly and evidence of the COFF image is ignored.
Reflecting on Managed Extensions for C++ executable files might throw a BadImageFormatException. This is most likely caused by C++ compiler stripping the relocation addresses or the .Reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- ReflectionPermission when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.
- FileIOPermission for access to read from a file or directory, and for access to the information in the path itself. Associated enumerations: FileIOPermissionAccess.Read, FileIOPermissionAccess.PathDiscovery.
- WebPermission for reading a URI that does not begin with "file://".
- SecurityPermission to load an assembly with evidence. Associated enumeration: SecurityPermissionFlag.ControlEvidence.