.NET application cannot start and receive XamlParseException

前端 未结 14 2548
小鲜肉
小鲜肉 2020-11-28 08:47

I wrote an app that can install and work on my development PC (a Window 7).

  • Development Environment: Window 7, VS2010 WPF C# with both .NET 4
14条回答
  •  一个人的身影
    2020-11-28 09:13

    XamlParseException is the generic error that happens when there is a problem at application start. I suggest you modify you application startup code to trace what's really going on and get, not only the XamlParseException, but also the inner exception(s) which should help you determine the root of the problem. Here is an example:

    namespace WpfApplication1
    {
        /// 
        /// Interaction logic for App.xaml
        /// 
        public partial class App : Application
        {
            protected override void OnStartup(StartupEventArgs e)
            {
                // hook on error before app really starts
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                base.OnStartup(e);
            }
    
            void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                // put your tracing or logging code here (I put a message box as an example)
                MessageBox.Show(e.ExceptionObject.ToString());
            }
        }
    }
    

提交回复
热议问题