好的,最後,我設法一起破解一些適合我的東西。也許這會有所幫助;
使用Assembly.GetExecutingAssembly,從具有我想要讀取的配置文件的DLL中,我可以使用.CodeBase在爲它啓動一個新的AppDomain之前找到DLL的位置。 * .dll .config位於同一個文件夾中。
然後必須轉換URI(如.CodeBase看起來像「file://path/assembly.dll」)以獲得ConfigurationManager的LocalPath(它不喜歡Uri格式化的字符串)。
try
{
string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
string originalAssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
Uri uri = new Uri(String.Format("{0}\\{1}.dll", originalAssemblyPath, assemblyName));
string dllPath = uri.LocalPath;
configuration = ConfigurationManager.OpenExeConfiguration(dllPath);
}
catch { }
我現在有同樣的問題,我不相信有一個解決方案。看到這個線程或多或少是同一個問題; http://stackoverflow.com/questions/636275/appdomain-and-config-section-typing –