C#建立DLL並且動態載入和動態卸載
C#建立DLL並且動態載入和動態卸載
資料來源:
00.http://codex.wiki/post/121123-558
01.https://dotblogs.com.tw/chou/2009/06/22/8930
02.https://social.msdn.microsoft.com/Forums/en-US/a6a896ca-8905-41fb-8f52-7f39e89c9a91/problem-loading-and-unloading-dynamically-an-assembly-dll-in-c?forum=csharplanguage
01.DLL 程式瑪
using System; namespace CS_ClassLibrary1 } |
02.EXE 程式瑪
using System; // Loader lives in another AppDomain loader.LoadAssembly(@”.\CS_ClassLibrary1.dll”); AppDomain.Unload(ad); Console.ReadLine(); class Loader : MarshalByRefObject public override object InitializeLifetimeService() public void LoadAssembly(string path) public object ExecuteStaticMethod(string fullClassName, string methodName, params Object[] args) Type tp = _assembly.GetType(fullClassName); MethodInfo method = tp.GetMethod(methodName); Object obj = Activator.CreateInstance(tp); return true; |