1

I need to break application settings in two files, one for external resources access, like a share folder or a web service url, and other for all the rest.

To keep configuration access simple in code i added a new Settings file, called ExternalResourceSettings. These settings files are derive from ApplicationSettingsBase.

How can i load an object of this class from a specific configuration file?

For clarification, the ExternalResourceSettings looks like these:

internal sealed partial class ExternalResourceSettings: global::System.Configuration.ApplicationSettingsBase {
...
}

ConfigurationManager class can load any config file to a Config object in 3 lines:

ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();                    
configFileMap.ExeConfigFilename = "Some path";

// Get the mapped configuration file
var config =ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

But how to convert it to ExternalResourceSettings? Or can ExternalResourceSettings be loaded from a specific file in a other way?

Note: ExternalResourceSettings default constructor reads from default configuration file.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
  • have a look at [this](https://social.msdn.microsoft.com/Forums/vstudio/en-US/78d8a9a4-9ff9-4154-8d60-c70b0f6a85ba/systemconfiguration-how-to-cast-appsettingssection-object-to-applicationsettingsbase-or?forum=netfxbcl) or [this](https://putridparrot.com/blog/user-application-settings-using-applicationsettingsbase/) – Matt.G Nov 19 '19 at 14:20
  • The solution presented is kind of brute force solution: Wrap all settings, one by one, in another class. I am looking for some solution built-in the framework to avoid doing all that work. – MiguelSlv Nov 19 '19 at 14:39
  • [Here](https://social.msdn.microsoft.com/Forums/en-US/78d8a9a4-9ff9-4154-8d60-c70b0f6a85ba/systemconfiguration-how-to-cast-appsettingssection-object-to-applicationsettingsbase-or?) as well it says the same thing – Matt.G Nov 19 '19 at 16:14
  • if you could use appsettings.json for ExternalResourceSettings, [this](https://stackoverflow.com/a/55019290/) could work.. – Matt.G Nov 19 '19 at 16:15
  • Yes, but is not a strong typed solution and not even avoids to use strings for keys. A wrapper class gives works but is better than just use appSettings. It is odd how there is no native solution. I am looking for packages now, packages that may extend configuration in this way. – MiguelSlv Nov 19 '19 at 16:18

0 Answers0