zoukankan      html  css  js  c++  java
  • 配置文件初始化异常Configuration system failed to initialize

    最近用户反映一些电脑启动程序就崩溃,还给演示了一个比较诡异的问题

    “把软件重新拷贝到另外一个目录,就能正常运行"。还说过一段时间又不能运行需要在换个位置。

    ’由于当时没有设置全局异常,只能借助系统操作日志来分析, 系统日志记录不全,就说发生一个异常程序挂掉。

    就简单加上全局异常捕获。 

    public class ExceptionHelper
        {
            public static void InitException()
            {
                Application.Current.DispatcherUnhandledException += Application_DispatcherUnhandledException;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            }
    
            private static void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
            {
                LogManager.WriteException(e.Exception);
                e.Handled = true;
            }
    
            private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                var exception = e.ExceptionObject as Exception;
                if (exception != null)
                {                
                    LogManager.WriteException(exception);
                }
            }
        }

    加入日志详细信息后,看到提示 Configuration system failed to initialize错误信息。然后借助搜索,找到一篇文章

    了解到原因两种:

    一、config 文件中 <configSections> 的位置顺序有关或者内容格式错误。

    二、包含了User作用域的配置项的时候,user.config文件损坏了。

    结合自己的程序确实用道<configSections>这个节点,用来保存程序在屏幕的位置,该节点已经在最上面,检测内容格式也是正常。

    那就剩下第二种可能了,找位置:C:UsersAdministratorAppDataLocalSuspendWpfApp,删除里面的文件即可

     Administrator:用户名, SuspendWpfApp:软件名。

    为了彻底解决这个问题,不在使用 Properties.Settings.Default来保存信息,自己用文件来保存上次信息。

    因为一旦userSettings出现问题,软件中依赖appSettings节点的信息将都获取不到。

  • 相关阅读:
    LeetCode OJ String to Integer (atoi) 字符串转数字
    HDU 1005 Number Sequence(AC代码)
    HDU 1004 Let the Balloon Rise(AC代码)
    HDU 1003 Max Sum(AC代码)
    012 Integer to Roman 整数转换成罗马数字
    011 Container With Most Water 盛最多水的容器
    010 Regular Expression Matching 正则表达式匹配
    007 Reverse Integer 旋转整数
    006 ZigZag Conversion
    005 Longest Palindromic Substring 最长回文子串
  • 原文地址:https://www.cnblogs.com/ColorsWin/p/13379435.html
Copyright © 2011-2022 走看看