我們加載組件(一個DLL)讀取一個配置文件。我們需要更改配置文件,然後重新加載程序集。我們發現第二次加載程序集後,配置沒有任何變化。 有人看到這裏有什麼問題嗎?我們在配置文件中省略了閱讀的細節。如何重新加載.NET應用程序域的程序集?
AppDomain subDomain;
string assemblyName = "mycli";
string DomainName = "subdomain";
Type myType;
Object myObject;
// Load Application domain + Assembly
subDomain = AppDomain.CreateDomain(DomainName,
null,
AppDomain.CurrentDomain.BaseDirectory,
"",
false);
myType = myAssembly.GetType(assemblyName + ".mycli");
myObject = myAssembly.CreateInstance(assemblyName + ".mycli", false, BindingFlags.CreateInstance, null, Params, null, null);
// Invoke Assembly
object[] Params = new object[1];
Params[0] = value;
myType.InvokeMember("myMethod", BindingFlags.InvokeMethod, null, myObject, Params);
// unload Application Domain
AppDomain.Unload(subDomain);
// Modify configuration file: when the assembly loads, this configuration file is read in
// ReLoad Application domain + Assembly
// we should now see the changes made in the configuration file mentioned above
爲什麼你的東東d在更新配置文件後重新加載組件?它是否包含動態創建的類型定義? – 2009-06-21 14:52:05
米奇 - 是的他們做 – 2009-06-23 07:49:48