user.config损坏问题 [英] user.config corruption issue

查看:68
本文介绍了user.config损坏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在桌面应用程序项目中,我们使用设置变量来存储应用程序的用户设置.此外,在应用程序的每个最新版本中,我们都会升级这些变量以保留用户设置.

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.

通常情况下,此方法工作正常,但最近我的一名最终用户报告了一个错误,即配置系统初始化失败.该错误与 user.config 文件有关.因此,我们要求用户将他的文件发送给我们.

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.

收到文件夹后,我们注意到该文件夹​​包含3个文件( c3begfjb.newcfg c3begfjb.tmp user.config ). c3begfjb.tmp 是一个空文件,而 c3begfjb.newcfg user.config 是相同的文件.我们试图打开这些文件,但 user.config 中的数据不是正确的xml,而是格式无法读取的文件.

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.

你们有没有遇到过这种问题,或者有任何想法如何以及如何创建这些文件并损坏了 user.config 文件.

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.

推荐答案

                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);
                }

这篇关于user.config损坏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆