0

I have a DLL that I need to be a part of the current AppDomain. Is there a way to signal the AppDomain to pick up dlls from some list in the app.config/web.config?

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
Byron Sommardahl
  • 12,743
  • 15
  • 74
  • 131

1 Answers1

3

You can put the name of the assembly in the app.config file and then load it up at run time using the Assembly.Load options and reflection. Here is a link to the MSDN article describing how to do this.

http://msdn.microsoft.com/en-us/library/25y1ya39.aspx

Basics

  1. Put name of assembly in app.config file
  2. Read entry using ConfigurationManager and get the name into a string in your program
  3. Pass the name of the assembly to the Assembly.Load method.

Example from the link:

public class Asmload0
{
    public static void Main()
    {
        // Use the file name to load the assembly into the current
        // application domain.
        Assembly a = Assembly.Load("example");
        // Get the type to use.
        Type myType = a.GetType("Example");
        // Get the method to call.
        MethodInfo myMethod = myType.GetMethod("MethodA");
        // Create an instance.
        object obj = Activator.CreateInstance(myType);
        // Execute the method.
        myMethod.Invoke(obj, null);
    }
}
tsells
  • 2,751
  • 1
  • 18
  • 20