0

当我试图为我的 app.config 获取一些东西时,我遇到了一个问题。

所以我的代码很简单:

ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap()
{
    ExeConfigFilename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
};

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
string value = config.AppSettings.Settings["test"].Value; // this is working
string value2 = System.Configuration.ConfigurationManager.AppSettings["test"]; // throw an exception

这里唯一棘手的事情是我的代码加载方式。C++ exe 在 AppDomain 中加载我的 C# 程序集并调用我的代码。

我有这种文件结构

  • 应用程序.exe (C++)
  • myDll.dll.config
  • 我的DLL.dll

问题是一些像 NLog 这样的库,例如调用ConfigurationManager.GetSection(),这会阻止记录器的初始化。

那么您对此有什么想法吗?

在此先感谢您的帮助 ;)

额外信息:

  • 网 4.7.2
  • 视窗 10
4

0 回答 0