views:

144

answers:

1

I have recently added a WCF service reference to my program. When I perform a clean install of this program, everything seems to work as expected. But, when I install the program on a client which already has a previous version (without the new service reference) installed, I get a exception telling me the default endpoint for this particular service could not be found.

It seems that the appname.exe.config is not being updated with the new endpoint settings. Is there any reason for this and how can I force the installer to overwrite the config file? I'm using the default Visual Studio 2008 installer project with RemovePreviousVersions set to True.

Update: My program encrypts the settings section after the first run with the following code

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConfigurationSection section = config.GetSection(sectionKey);
        if (section != null)
        {
            if (!section.SectionInformation.IsProtected)
            {
                if (!section.ElementInformation.IsLocked)
                {
                    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                    section.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);
                }
            }
        }

When I do not run the program before installing the new version the app.config gets updated.

A: 

You are right that it is the config file that is not updated.

There are several possibilities:

  • The installer has the old version of the config file
  • The installer does not have a config file and the program is using the old one on the machine

Try uninstalling the project first, then install and check that the config file has been copied in.

Shiraz Bhaiji
I have tried that already and the config file is being copied. The application works fine when I first uninstall it. It also works when I delete the current config file and update afterwards.
Boesj
Check that you do not have several copies of the program or config file on the machine
Shiraz Bhaiji
I've just installed the old version on a clean pc, ran the program, closed it and installed the new version. The same error occured. After that, I uninstalled the program and this time did the same but without running the program and it worked. My app.config file contains an encrypted settings section. Could this cause the trouble?
Boesj
Yes that could be it. The encryption is done using a machine key, but the key is different on each machine. There is a way to make the machine key the same on many machines, normally used on web servers.
Shiraz Bhaiji
That wouldn't resolve the problem, since the config files are encrypted already and I have to update existing installations
Boesj