title: C++/CLI Explicitly Load Managed DLL at runtime (the equivalent of LoadLibrary for Unmanaged)
body: <p><strong>Problem 1:</strong></p>
  
  <p>Is there a way to explicitly load a library at runtime instead of at compile time in C++/CLI. Currently I am using the .NET "Add Reference" at compile time.
  I would like to explicitly load a managed dll. Is there the .NET equivalent of LoadLibrary?</p>
  
  <p><strong>Update:</strong> Thanks to Randolpho</p>
  
  <p>Assembly::LoadFrom example from <a href="http://msdn.microsoft.com/en-us/library/1009fa28.aspx" rel="noreferrer">MSDN</a></p>
  
  <pre><code>Assembly^ SampleAssembly;
  SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" );
  // Obtain a reference to a method known to exist in assembly.
  MethodInfo^ Method = SampleAssembly-&gt;GetTypes()[ 0 ]-&gt;GetMethod( "Method1" );
  // Obtain a reference to the parameters collection of the MethodInfo instance.
  array&lt;ParameterInfo^&gt;^ Params = Method-&gt;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-&gt;Name );
     Console::WriteLine( "  Type= {0}", Param-&gt;ParameterType );
     Console::WriteLine( "  Position= {0}", Param-&gt;Position );
     Console::WriteLine( "  Optional= {0}", Param-&gt;IsOptional );
  }
  </code></pre>
  
  <p><strong>Problem 2:</strong> </p>
  
  <p>If Assembly::LoadFrom is the .NET equivalent of LoadLibrary. What is the equivalent of GetProcAddress? How do I create FunctionPointers to the methods?</p>
  
  <p><strong>Update:</strong> MethodBase.Invoke from <a href="http://msdn.microsoft.com/en-us/library/a89hcwhh.aspx" rel="noreferrer">MSDN</a></p>
  
  <pre><code>using namespace System;
  using namespace System::Reflection;
  
  public ref class MagicClass
  {
  private:
      int magicBaseValue;
  
  public:
      MagicClass()
      {
          magicBaseValue = 9;
      }
  
      int ItsMagic(int preMagic)
      {
          return preMagic * magicBaseValue;
      }
  };
  
  public ref class TestMethodInfo
  {
  public:
      static void Main()
      {
          // Get the constructor and create an instance of MagicClass
  
          Type^ magicType = Type::GetType("MagicClass");
          ConstructorInfo^ magicConstructor = magicType-&gt;GetConstructor(Type::EmptyTypes);
          Object^ magicClassObject = magicConstructor-&gt;Invoke(gcnew array&lt;Object^&gt;(0));
  
          // Get the ItsMagic method and invoke with a parameter value of 100
  
          MethodInfo^ magicMethod = magicType-&gt;GetMethod("ItsMagic");
          Object^ magicValue = magicMethod-&gt;Invoke(magicClassObject, gcnew array&lt;Object^&gt;(1){100});
  
          Console::WriteLine("MethodInfo.Invoke() Example\n");
          Console::WriteLine("MagicClass.ItsMagic() returned: {0}", magicValue);
      }
  };
  
  int main()
  {
      TestMethodInfo::Main();
  }
  </code></pre>