好的,最后,我设法一起破解一些适合我的东西。也许这会有所帮助;
使用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 –