Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid version specific information in configSection in app.config

I have made a small GUI for administration of some settings in an app.config file. The GUI is released as part of my product, making it possible to change values in the app.config file, without opening this in a text editor.

The properties are implemented in a custom configSection, making it strongly typed in the code. My problem is, that when the app.config file is updated (when I save from the GUI), the fully qualified name of my assembly is written in the configSection like this:

<section name="ConfigurationSettings" type="PerformanceDude.MSBuildShellExtension.Common.ConfigurationSettings, Common, Version=2.2.1.0, Culture=neutral, PublicKeyToken=1ab1b15115e63xxx" />

When I upgrade this assembly to a new version number, the GUI code assembly version not longer matches the assembly references in the app.config.

This is how I load the settings:

var config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = ConfigFilePath }, ConfigurationUserLevel.None);
var settings = Config.GetSection("ConfigurationSettings") as ConfigurationSettings;

This is how I save the settings:

config.Save(ConfigurationSaveMode.Minimal, true);

I don't want to write an upgrade script changing the version everytime I update. Does anyone know a great solution to this problem?

like image 381
ThomasArdal Avatar asked Jul 02 '12 15:07

ThomasArdal


1 Answers

I've had to do a similar thing before. I ended up loading the config file as xml, de-serializing the relevant sections into objects, then putting them back into the xml. Avoiding the .net configuration API in that way avoid issues with the version.

Another approach is to redirect the old version of the assembly to a new version. If your assembly is in the GAC, you can use policy files to do this, and deploy them when you deploy a new version; then the version numbers in the config won't matter.

like image 83
tallseth Avatar answered Sep 23 '22 03:09

tallseth