There is such an app.config file in Appendix "A":

<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="AutoCalcService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> </sectionGroup> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="AutoCalcService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup> <userSettings> <AutoCalcService.Properties.Settings> <setting name="RoutesOptimize" serializeAs="String"> <value>False</value> </setting> <setting name="NotificationSender" serializeAs="String"> <value>value1</value> </setting> <setting name="NotificationTitle" serializeAs="String"> <value>value2</value> </setting> <setting name="NotificationMessage" serializeAs="String"> <value>value3</value> </setting> </AutoCalcService.Properties.Settings> </userSettings> <applicationSettings> <AutoCalcService.Properties.Settings> <setting name="NotificationGoogleAppId" serializeAs="String"> <value>value4</value> </setting> </AutoCalcService.Properties.Settings> </applicationSettings> 

Task: to access it from application "B", which is in no way connected with it, and allow application "B" to edit the settings in section of application "A" (the section is read-only) - that is, make admin panel! The ability to architecturally render app.config into a separate application and "inherit" both "A" and "B" from it - alas, no.

I managed to get the Configuration itself and even its individual sections like this:

 string otherExePath = @"DLAutoCalcService.exe"; Configuration otherConfig = ConfigurationManager.OpenExeConfiguration(otherExePath); var sectgr = otherConfig.SectionGroups["userSettings"]; var sect = sectgr.Sections["AutoCalcService.Properties.Settings"]; 

The sectgr (ConfigurationSectionGroup type) and sect (ConfigurationSection type) objects are not null, and the sect even has my settings, but I cannot “reach out” to them. In sect public members, the Settings property (as seen in the screenshot) is missing.

enter image description here

Please help me continue my code until getting, changing and saving changes using the example of setting "RoutesOptimize".

  • The phrase "and allow application" B "to edit the settings in the section of application" A "(the section is read only)" - read as - "and allow application" B "to edit the settings in the section" userSetting "of application" A "(section" applicationSettings "read only)" - Andrey Kutasevich
  • Please use the "edit" button instead of writing comment-corrections. - Pavel Mayorov

1 answer 1

Something like this:

 var sectgr = otherConfig.SectionGroups["userSettings"]; ClientSettingsSection sect = (ClientSettingsSection)sectgr.Sections["AutoCalcService.Properties.Settings"]; //чтение var element = sect.Settings.Get("RoutesOptimize").Value.ValueXml; textBox1.Text = element.InnerXml; //запись element.InnerText = "True"; sect.SectionInformation.ForceSave = true; otherConfig.Save(); 
  • Thank you very much! Although this kind of handling of configuration (via xml) looks strange, it works and helped me. - Andrey Kutasevich