Question

I'm posting my question here and to CodeProject, as a question to the famous article series on the mysteries of config files.

From the article:

Optionally, you may specify culture, version and public key (for signed assemblies) values if you wish to ensure only a specific version of an assembly is searched for when your .config file is parsed.

I'm using the following code to open and initialize the config file:

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = path;
config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
section = (OptionsSection)config.GetSection("myoptionsdata");
if (section == null)
{
    section = new OptionsSection(0, "aaaa", "bbbb", "cccc",14);
    config.Sections.Add("myoptionsdata", section);
    config.Save(ConfigurationSaveMode.Full);
}

That creates the following:

<configSections>
    <section name="myoptionsdata" type="my.namespace.OptionsSection, myAssembly,
      Version=1.0.3.0, Culture=neutral, PublicKeyToken=111222aaaabbb"
      allowLocation="true" allowDefinition="Everywhere"
      allowExeDefinition="MachineToApplication" overrideModeDefault="Allow"
      restartOnExternalChanges="true" requirePermission="true" />
</configSections>

Notice how the 'type' has Version, Culture, and the PublicKeyToken. I need to eliminate these, or at least the Version. The problem is that I deploy the app with a specific version, then I bump the version and issue updates. But when the read is done on the config it fails because the version is explicit.

So really all I want is this:

<configSections>
    <section name="myoptionsdata" type="my.namespace.OptionsSection, myAssembly" />
</configSections>

I have never once seen an example that includes the extended type values. Every example shows Save() creating type="namespace.class,assembly", and yet that doesn't seem to be the default behavior.

So, with reference to the above quote, where can I find information on managing those "optional" values?

For anyone googling, this is one of the causes of the infamous error below:

Exception: An error occurred creating the configuration section handler for myoptionsdata: Could not load file or assembly 'myAssembly, Version=1.0.3.0, Culture=neutral, PublicKeyToken=111222aaaabbb' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\Users\me\AppData\Roaming\product\dir\name.config line 4)

I believe my question is similar to this one which so far has not received any response.

Going "off the menu", I just want to deploy a config file to a specific location (non-default) and allow users to set options in a Tools>Options sort of form. Most apps do this. Is there any easy and commonly accepted way of doing this? I should note that my app is an Outlook Addin, and I do my config file like this because I want to store addin settings in an addin-specific config file rather than anywhere near Outlook configs.

Was it helpful?

Solution

The assembly that contains your custom configuration section has a strong name. Strong-naming an assembly explicitly prevents the kind of in-place version upgrade you want to do. Remove the strong name from that assembly and the assembly loader will stop caring what version it is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top