3

In our desktop application projects we use setting variables to store user setting for the applications. Moreover, with every latest version of the applications, we upgrade these variables to retain user settings.

Normally, this works fine, but recently one of my end user reported an error i.e. Configuration System failed to initialize. The error is related to user.config file. Therefore we requested the user to send us his file.

After received the folder, we noticed that it contains 3 files (c3begfjb.newcfg, c3begfjb.tmp and user.config). c3begfjb.tmp is an empty file, while c3begfjb.newcfg and user.config are identical files. We tried to open these files but the data in user.config isn’t proper xml rather its unreadable formatted file.

Do any you guys had experienced this sort of issue or any ideas how and what may have created these files and corrupted user.config file.

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
Maverick
  • 83
  • 1
  • 5
  • 2
    Disks go bad, nothing unusual. Tell your user to fix his machine. – Hans Passant Feb 14 '12 at 07:23
  • 2
    @Maverick - I feel your pain. I have an application that suffers from this issue quite frequently. Usually users tell me it happens during a restart, possibly Windows update auto reboot. This also appears to be a duplicate of http://stackoverflow.com/questions/868653/corruption-of-user-config – harlam357 Mar 23 '12 at 03:38

2 Answers2

3
                try
                {
                    // preloads the settings file and throws an error if the settings file is corrupted
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
                }
                catch (ConfigurationErrorsException ex)
                {
                   File.Delete(ex.Filename);
                }
TrustyCoder
  • 4,749
  • 10
  • 66
  • 119
  • 1
    delete the file if corrupt settings file is detected. the above code snippet does that. – TrustyCoder Oct 03 '14 at 16:45
  • 1
    This will actually throw an exception in cases other than when the user.config file is actually corrupted. For example, if another instance of the application already has a file lock on user.config, ConfigurationErrorsException is thrown even though user.config is not corrupt. You should check the inner exception (IOException in this example) before proceeding with the deleting. – OfficeAddinDev Sep 27 '16 at 23:02
0

This article may be helpful.

https://www.codeproject.com/Articles/30216/Handling-Corrupt-user-config-Settings

Basically the process is to check if config is not corrupted, if not, it resets config.

Tejasvi Hegde
  • 2,694
  • 28
  • 20