I´ve read this post from Marc Gravell showing how to read an app.config
-file from a DLL. When I try to read the userSettings
from within that library I get an empty list:
var settings = ConfigurationManager.OpenExeConfiguration("CodeGeneratorApp.exe").AppSettings.Settings;
The app.config
-file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="CodeGenerator.CodeGeneratorApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<CodeGenerator.CodeGeneratorApp.Properties.Settings>
<setting name="CodeExtensions" serializeAs="Xml">
<value>
<CodeExtensionList>
<Extension AssemblyQualifiedName="CodeGenerator.Extensions.NamespaceTypesExtension, CodeGenerator, Culture=neutral">
<NamespaceTypesExtension />
</Extension>
...
</CodeExtensionList>
</value>
</setting>
</CodeGenerator.CodeGeneratorApp.Properties.Settings>
</userSettings>
</configuration>
My DLL and the application are located in the same folder and even when I add
var settings = ConfigurationManager.OpenExeConfiguration("CodeGeneratorApp.exe").AppSettings.Settings;
to a QuickWatch I see that the FilePath
of the returned object is set to the applications config-file, so it was found and opened properly.
In particular what I´m trying to achieve is to de-serialize the value
for CodeExtensionList
but I don´t know how to even access that section within the file.