【发布时间】:2012-04-22 22:57:47
【问题描述】:
我有一个 DLL,我需要成为当前 AppDomain 的一部分。有没有办法让 AppDomain 从 app.config/web.config 中的某个列表中获取 dll?
【问题讨论】:
标签: c# reflection assemblies app-config appdomain
我有一个 DLL,我需要成为当前 AppDomain 的一部分。有没有办法让 AppDomain 从 app.config/web.config 中的某个列表中获取 dll?
【问题讨论】:
标签: c# reflection assemblies app-config appdomain
您可以将程序集的名称放在 app.config 文件中,然后在运行时使用 Assembly.Load 选项和反射加载它。这是 MSDN 文章的链接,该文章描述了如何执行此操作。
http://msdn.microsoft.com/en-us/library/25y1ya39.aspx
基础知识
链接示例:
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);
}
}
【讨论】: