Export (0) Print
Expand All

Assembly.LoadFrom Method

Loads an assembly.

Overload List

Loads an assembly given its file name or path.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function LoadFrom(String) As Assembly
[C#] public static Assembly LoadFrom(string);
[C++] public: static Assembly* LoadFrom(String*);
[JScript] public static function LoadFrom(String) : Assembly;

Loads an assembly given its file name or path and supplying security evidence.

[Visual Basic] Overloads Public Shared Function LoadFrom(String, Evidence) As Assembly
[C#] public static Assembly LoadFrom(string, Evidence);
[C++] public: static Assembly* LoadFrom(String*, Evidence*);
[JScript] public static function LoadFrom(String, Evidence) : Assembly;

Loads an assembly given its file name or path, security evidence hash value, and hash algorithm.

[Visual Basic] Overloads Public Shared Function LoadFrom(String, Evidence, Byte(), AssemblyHashAlgorithm) As Assembly
[C#] public static Assembly LoadFrom(string, Evidence, byte[], AssemblyHashAlgorithm);
[C++] public: static Assembly* LoadFrom(String*, Evidence*, unsigned char __gc[], AssemblyHashAlgorithm);
[JScript] public static function LoadFrom(String, Evidence, Byte[], AssemblyHashAlgorithm) : Assembly;

Example

The following example loads an assembly given its file name or path.

[Visual Basic] 
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

[C#] 
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());
}

[C++] 
Assembly* SampleAssembly;
SampleAssembly = Assembly::LoadFrom(S"c:\\Sample.Assembly.dll");
// Obtain a reference to a method known to exist in assembly.
MethodInfo* Method = SampleAssembly->GetTypes()[0]->GetMethod(S"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
IEnumerator* myEnum = Params->GetEnumerator();
while (myEnum->MoveNext()) {
   ParameterInfo* Param = __try_cast<ParameterInfo*>(myEnum->Current);

   Console::WriteLine(S"Param= {0}", Param->Name);
   Console::WriteLine(S"  Type= {0}", Param->ParameterType);
   Console::WriteLine(S"  Position= {0}", __box(Param->Position));
   Console::WriteLine(S"  Optional= {0}", __box(Param->IsOptional));
}

[JScript] 
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());
}

See Also

Assembly Class | Assembly Members | System.Reflection Namespace

Show:
© 2014 Microsoft