简体   繁体   中英

Corruption of user.config

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.

您是否尝试过Properties.Setting.default.reset()

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. 自动保存设置 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM