0

Anyone knows the reason of "random" user.config corruption? I've a WinForms app affected by this problem at my client's production line. Found the same issue on the web and a workaround but I can't figure out because it happens.

Andrea Balducci
  • 2,834
  • 1
  • 21
  • 18

3 Answers3

0

Did you try Properties.Setting.default.reset()?

Echilon
  • 10,064
  • 33
  • 131
  • 217
RedPanda
  • 135
  • 7
0

The main Idea is to prevent save setting when the application exit. to do that you need to save all the setting once it change by issue my.setting.save. There is setting in the application to auto save the setting when exit the application. auto save setting also you can add on application start to check if the setting is corrupted then delete the file and restart the application

        Try
            Dim a = My.Settings.Language
        Catch ex As System.Configuration.ConfigurationErrorsException
            Dim filename As String = TryCast(ex.InnerException, System.Configuration.ConfigurationErrorsException).Filename
            System.IO.File.Delete(filename)
            MySettings.Default.Reload()
            System.Windows.Forms.Application.Restart()
        End Try
0

I'm not sure why it's happening, but you are not alone, dude! I also tried different things to get around this. I wrote my own configuration handling classes with custom serialization. All I can tell you is, it's better but now still there.

One observation I made recently is that the corruption seems to happen when the machine is rebooted (due to Windows Updates for example) while my app is running.

Next thing to try is to catch those shutdown events and try not to write to the config file in this situation.

Stefan Koell
  • 1,476
  • 3
  • 15
  • 25