Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 我在App.cs中的DispatcherUnhandledExceptionEventHandler中捕获异常,因此我不';我不知道是哪条线扔的_.net_Wpf_Exception - Fatal编程技术网

.net 我在App.cs中的DispatcherUnhandledExceptionEventHandler中捕获异常,因此我不';我不知道是哪条线扔的

.net 我在App.cs中的DispatcherUnhandledExceptionEventHandler中捕获异常,因此我不';我不知道是哪条线扔的,.net,wpf,exception,.net,Wpf,Exception,这是我得到的一个例外。 我在一个DispatcherUnhandledExceptionEventHandler中捕捉到它 在App.cs中,所以我现在不知道是哪条线抛出的 有没有关于如何追踪和修复的建议? 没有内在的例外 e.Exception.GetBaseException().Message Object reference not set to an instance of an object. e.Exception.StackTrace at System.Wi

这是我得到的一个例外。
我在一个DispatcherUnhandledExceptionEventHandler中捕捉到它
在App.cs中,所以我现在不知道是哪条线抛出的
有没有关于如何追踪和修复的建议? 没有内在的例外

e.Exception.GetBaseException().Message Object 
reference not set to an instance of an object.


e.Exception.StackTrace    
   at System.Windows.Controls.ItemContainerGenerator.MoveToPosition(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem, GeneratorState& state)
   at System.Windows.Controls.ItemContainerGenerator.Generator..ctor(ItemContainerGenerator factory, GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)


void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("App_DispatcherUnhandledException");
    System.Diagnostics.Debug.WriteLine("(e == null) = " + (e == null).ToString());
    System.Diagnostics.Debug.WriteLine("e.ToString() " + e.ToString());
    System.Diagnostics.Debug.WriteLine("e.Exception.GetBaseException().Message " + e.Exception.GetBaseException().Message);
    System.Diagnostics.Debug.WriteLine("e.Exception.GetBaseException().InnerException " + e.Exception.GetBaseException().InnerException);
    System.Diagnostics.Debug.WriteLine("e.Exception.GetBaseException().Source " + e.Exception.GetBaseException().Source.ToString());
    System.Diagnostics.Debug.WriteLine("e.Exception.StackTrace " + e.Exception.StackTrace.ToString());
    System.Diagnostics.Debug.WriteLine("e.Exception.GetBaseException().StackTrace " + e.Exception.GetBaseException().StackTrace.ToString());
    StringBuilder sb = new StringBuilder();
    if (e.Exception.InnerException != null)
    {
        sb.AppendLine("InnerException");
        sb.AppendLine(e.Exception.InnerException.Message);
        if (!string.IsNullOrEmpty(e.Exception.InnerException.StackTrace))
        {
            int count = 0;
            foreach (string line in e.Exception.InnerException.StackTrace.Split('\n'))
            {
                sb.AppendLine(line.Trim());
                count++;
                if (count > 3) break;
            }
        }
    }
    sb.AppendLine("OuterException");
    sb.AppendLine(e.Exception.Message);
    if (!string.IsNullOrEmpty(e.Exception.StackTrace))
    {
        int count = 0;
        foreach (string line in e.Exception.StackTrace.Split('\n'))
        {
            sb.AppendLine(line.Trim());
            count++;
            if (count > 3) break;
        }
    }
    MessageBox.Show(sb.ToString(), "App_DispatcherUnhandledException");
    e.Handled = true;
    if (MainWindow != null) MainWindow.Close();
}

当你调用一行代码,比如

e.Exception.GetBaseException().Message
您必须首先确保GetBaseException()实际返回一个对象


根据堆栈跟踪,这就是问题所在。我对此持怀疑态度,因为MSDN文档指出
GetBaseException()
应该始终返回一个对象(如果您实际上正在处理一个尚未解开的实际异常)。

当您调用一行类似

e.Exception.GetBaseException().Message
您必须首先确保GetBaseException()实际返回一个对象


根据堆栈跟踪,这就是问题所在。我对此持怀疑态度,因为MSDN文档指出
GetBaseException()
应该始终返回一个对象(如果您实际上正在处理尚未解开的实际异常)。

您能在调试器中运行它吗?暂时注释掉您的异常处理程序,或将Visual Studio设置为在引发CLR异常时中断。是否可以显示异常处理程序?到目前为止,我无法在调试器中使其出错。请在Visual Studio的“调试”菜单上单击“异常”项。选中“引发公共语言运行时异常”列中的复选框。您可以在调试器中运行它吗?暂时注释掉您的异常处理程序,或者在引发CLR异常时将Visual Studio设置为中断。您可以显示您的异常处理程序吗?到目前为止,我无法使其在调试器中出错。在Visual Studio的“调试”菜单上,单击例外项。选中抛出列中的框,查看公共语言运行时异常。谢谢,我会尝试的。但是我仍然需要追踪未处理的异常来自何处。当然。但是如果你解决了处理程序的问题,原始异常的性质应该会变得更加明显(因为新异常掩盖了原始异常)。我只需要到达那里进行验证。我无法让它抛出一个包含null GetBaseException()的异常进行验证,但我怀疑(希望)这就是答案。谢谢,我会尝试的。但是我仍然需要追踪未处理的异常来自何处。当然。但是如果你解决了处理程序的问题,原始异常的性质应该会变得更加明显(因为新异常掩盖了原始异常)。我只需要到达那里进行验证。我无法让它抛出一个包含null GetBaseException()的异常进行验证,但我怀疑(希望)这就是答案。