这是我得到的一个例外。
我
在 App.cs 中的 DispatcherUnhandledExceptionEventHandler 中捕获了它,所以我现在不知道哪条线正在抛出它
关于如何追踪并修复它的任何建议?没有内部异常
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();
}