Loads an assembly given its file name or path.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Shared Function LoadFrom ( _
assemblyFile As String _
) As Assembly
Dim assemblyFile As String
Dim returnValue As Assembly
returnValue = Assembly.LoadFrom(assemblyFile)
public static Assembly LoadFrom (
string assemblyFile
)
public:
static Assembly^ LoadFrom (
String^ assemblyFile
)
public static Assembly LoadFrom (
String assemblyFile
)
public static function LoadFrom (
assemblyFile : String
) : Assembly
Parameters
- assemblyFile
The name or path of the file that contains the manifest of the assembly.
Return Value
The loaded assembly.
The assemblyFile parameter must refer to a URI without escape characters. This method supplies escape characters for all invalid characters in the URI.
assemblyFile is relative to the current directory, and the assembly is loaded into the domain of the caller.
The LoadFrom method has the following disadvantages. Consider using Load instead.
-
If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.
-
If an assembly is loaded with LoadFrom, and later an assembly in the load context attempts to load same the assembly by display name, the load attempt fails. This can occur when an assembly is de-serialized.
-
If an assembly is loaded with LoadFrom, and the probing path includes an assembly with the same identity but a different location, an InvalidCastException, MissingMethodException, or other unexpected behavior can occur.
-
LoadFrom demands Read and F:System.Security.Permissions.FileIOPermissionAccess.PathDiscovery, or WebPermission, on the specified path.
-
If a native image exists for assemblyFile, it is not used. The assembly cannot be loaded as domain neutral.
-
In the .NET Framework version 1.0 and 1.1, policy is not applied.
The following example loads an assembly given its file name or path.
Dim SampleAssembly As [Assembly]
SampleAssembly = [Assembly].LoadFrom("c:\Sample.Assembly.dll")
' Obtain a reference to a method known to exist in assembly.
Dim Method As MethodInfo = SampleAssembly.GetTypes()(0).GetMethod("Method1")
' Obtain a reference to the parameters collection of the MethodInfo instance.
Dim Params As ParameterInfo() = Method.GetParameters()
' Display information about method parameters.
' Param = sParam1
' Type = System.String
' Position = 0
' Optional=False
Dim Param As ParameterInfo
For Each Param In Params
Console.WriteLine(("Param=" + Param.Name.ToString()))
Console.WriteLine((" Type=" + Param.ParameterType.ToString()))
Console.WriteLine((" Position=" + Param.Position.ToString()))
Console.WriteLine((" Optional=" + Param.IsOptional.ToString()))
Next Param
Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");
// Obtain a reference to the parameters collection of the MethodInfo instance.
ParameterInfo[] Params = Method.GetParameters();
// Display information about method parameters.
// Param = sParam1
// Type = System.String
// Position = 0
// Optional=False
foreach (ParameterInfo Param in Params)
{
Console.WriteLine("Param=" + Param.Name.ToString());
Console.WriteLine(" Type=" + Param.ParameterType.ToString());
Console.WriteLine(" Position=" + Param.Position.ToString());
Console.WriteLine(" Optional=" + Param.IsOptional.ToString());
}
Assembly^ SampleAssembly;
SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" );
// Obtain a reference to a method known to exist in assembly.
MethodInfo^ Method = SampleAssembly->GetTypes()[ 0 ]->GetMethod( "Method1" );
// Obtain a reference to the parameters collection of the MethodInfo instance.
array<ParameterInfo^>^ Params = Method->GetParameters();
// Display information about method parameters.
// Param = sParam1
// Type = System::String
// Position = 0
// Optional=False
for each ( ParameterInfo^ Param in Params )
{
Console::WriteLine( "Param= {0}", Param->Name );
Console::WriteLine( " Type= {0}", Param->ParameterType );
Console::WriteLine( " Position= {0}", Param->Position );
Console::WriteLine( " Optional= {0}", Param->IsOptional );
}
var SampleAssembly : Assembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
var Method : MethodInfo = SampleAssembly.GetTypes()[0].GetMethod("Method1");
// Obtain a reference to the parameters collection of the MethodInfo instance.
var Params : ParameterInfo[] = Method.GetParameters();
// Display information about method parameters.
// Param = sParam1
// Type = System.String
// Position = 0
// Optional=False
for (var i : int in Params){
var Param : ParameterInfo = Params[i];
Console.WriteLine("Param=" + Param.Name.ToString());
Console.WriteLine(" Type=" + Param.ParameterType.ToString());
Console.WriteLine(" Position=" + Param.Position.ToString());
Console.WriteLine(" Optional=" + Param.IsOptional.ToString());
}
- FileIOPermission
for reading a URI that begins with "file://". Associated enumeration: FileIOPermissionAccess.Read
- WebPermission
for reading a URI that does not begin with "file://".
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
.NET Framework
Supported in: 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 2.0, 1.0