Export (0) Print
Expand All

AppDomain.Load Method (AssemblyName)

Loads an Assembly given its AssemblyName.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public:
virtual Assembly^ Load (
	AssemblyName^ assemblyRef
) sealed
public final Assembly Load (
	AssemblyName assemblyRef
)
public final function Load (
	assemblyRef : AssemblyName
) : Assembly
Not applicable.

Parameters

assemblyRef

An object that describes the assembly to load.

Return Value

The loaded assembly.

Exception typeCondition

ArgumentNullException

assemblyRef is a null reference (Nothing in Visual Basic).

FileNotFoundException

assemblyRef is not found.

BadImageFormatException

assemblyRef is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and assemblyRef was compiled with a later version.

AppDomainUnloadedException

The operation is attempted on an unloaded application domain.

FileLoadException

An assembly or module was loaded twice with two different evidences.

This method should only be used to load an assembly into the current application domain. This method is defined for interoperability callers who cannot call the static Load method.

If a version of the requested assembly is already loaded, this method returns the loaded assembly, even if a different version is requested.

Supplying a partial assembly name for assemblyRef is not recommended. (A partial name omits one or more of culture, version, or public key token. For overloads that take a string instead of an AssemblyName object, "MyAssembly, Version=1.0.0.0" is an example of a partial name and "MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=18ab3442da84b47" is an example of a full name.) Using partial names has a negative effect on performance. In addition, a partial assembly name can load an assembly from the global assembly cache only if there is an exact copy of the assembly in the application base directory (BaseDirectory or AppDomainSetup.ApplicationBase).

If the current AppDomain object represents application domain A, and the Load method is called from application domain B, the assembly is loaded into both application domains. For example, the following code loads MyAssembly into the new application domain ChildDomain and also into the application domain where the code executes:

    Dim ad As AppDomain = AppDomain.CreateDomain("ChildDomain")
    ad.Load("MyAssembly")

    AppDomain ad = AppDomain.CreateDomain("ChildDomain");
    ad.Load("MyAssembly");

    AppDomain^ ad = AppDomain::CreateDomain("ChildDomain");
    ad->Load("MyAssembly");

The assembly is loaded into both domains because Assembly does not derive from MarshalByRefObject, and therefore the return value of the Load method cannot be marshaled. Instead, the common language runtime tries to load the assembly into the calling application domain. The assemblies that are loaded into the two application domains might be different if the path settings for the two application domains are different.

NoteNote:

If both the AssemblyName.Name property and the AssemblyName.CodeBase property are set, the first attempt to load the assembly uses the display name (including version, culture, and so on, as returned by the Assembly.FullName property). If the file is not found, the CodeBase property is used to search for the assembly. If the assembly is found using CodeBase, the display name is matched against the assembly. If the match fails, a FileLoadException is thrown.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft