我有数个 dll 文件, 主程序需在程序判断在使用动态 Reflection 加载何种 dll 檔Assembly dllFile = System.Reflection.Assembly.LoadFrom(@"dll_01.dll");
Type thetype = dllFile.GetType("dll01.Message_Show");switch (i)
{
    case 0:
    {
          dllFile = System.Reflection.Assembly.LoadFrom(@"dll_01.dl");
          thetype = dllFile.GetType("dll01.Message_Show");
          break;
     }     case 1:
     {
          dllFile = System.Reflection.Assembly.LoadFrom(@"dll_02.dll");
          thetype = dllFile.GetType("dll_02.Message_Show");
          break;
      }
      ….
      ….
}
                
可是这样加载dll 会在一开始加载一次, 在 switch case 里再加载一次,
请问有没有办法在第一次加载 dll 后卸载, 或是在一开始只做宣告而不加载dll?

解决方案 »

  1.   

    用System.Reflection.Assembly.Load 动态加载程序集(.exe或dll)
    Assembly a = Assembly.LoadFrom("a.exe");
    用AppDomain.Unload 方法 卸载指定的应用程序域中的所有程序集。
      

  2.   

    不太了解楼上说的要如何实行
    假设我现今已加载 test.dll
    Assembly dllFile = System.Reflection.Assembly.LoadFrom("test.dll");
    Type thetype = dllFile.GetType("test.Message_Show");要如何用AppDomain 去卸载?