程序在系统盘能运行不能在非系统盘运行

解决方法:

在.net程序的主程序中添加捕捉异常;

 
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            #region[捕获未捕捉到的异常]
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            #endregion
            Application.Run(new MainFrame());
        }

        static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            MessageBox.Show(e.Exception.Message, "Unhandled Thread Exception");
            // here you can log the exception ...
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show((e.ExceptionObject as Exception).Message, "Unhandled UI Exception");
            // here you can log the exception ...
        }
    }

捕捉到的异常为“配置系统未能初始化”;

这说明是配置文件出错或者读取的不是本程序的配置文件,参考  http://blog.csdn.net/hustypf/article/details/7718948,将可能会影响的配置文件删除。

 

posted on 2016-12-20 14:21  RunRock  阅读(184)  评论(0)    收藏  举报

导航