У меня есть приложение WPF (mvvm) с несколькими проектами. В основном проекте у меня есть файл App.config. Я добавил пару настроек через Settings.settings. Файл App.config выглядит так:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="VSAutomation.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<section name="log4net" type="log4net.config.Log4NetConfigurationSectionHandler, log4net" />
log4net stuff here...
<applicationSettings>
<VSAutomation.Properties.Settings>
<setting name="SimDir" serializeAs="String">
<value>"C:\Program Files (x86)\sim"</value>
</setting>
</VSAutomation.Properties.Settings>
</applicationSettings>
Когда я пытаюсь получить доступ к этим настройкам из одного из других модулей
string appFolder = ConfigurationManager.AppSettings.Get("SimDir");
Он возвращает ноль. Если я установил точку останова и оценил
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
Он указывает на правильный файл appname.exe.config и настройки верны.
ConfigurationManager.AppSettings.Count
возвращает 0
Это действительно странно. Я рассмотрел десятки вопросов здесь, StackOverflowflow, но не нашел решения. Это связано с разделом log4net
?
VSAutomation.Properties.Settings.SimDir
- person Szabolcs Dézsi   schedule 28.10.2017