电源故障或不正确关闭后,配置系统无法初始化(user.config)

时间:2016-10-28 13:49:11

标签: c# .net winforms configuration settings

我意识到SO上有几个主题几乎相同的标题,尽管没有描述我的一些用户体验的行为。

使用visual studio的内置设置,将所有设置设置为“用户范围”

  

下一个异常只会出现,通常是在计算机关闭不当时(有人在不关闭Windows的情况下关闭计算机)。

     

停电也是另一个可能原因。

设置在启动时加载并保存在表单关闭。

例外摘要

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Data at the root level is invalid. Line 1, position 1. (C:\Users\USERNAME\AppData\Local\APPLICATIONNAME.exe_Url_dbamatfk4dvaz3ykr4crkwlnzkz0kr4g\1.12.2.1\user.config line 1) ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.

这只能通过删除user.config文件(在上面提到的文件夹中)来修复,因为文件似乎已损坏并重新启动应用程序(此时将重建用户设置)。在此阶段,所有设置都会再次默认。

问题:

为什么在出现电源故障或系统关闭错误时配置文件会损坏?

我能以任何方式防止这种情况发生吗?

0 个答案:

没有答案