我从客户那里得到了下面的堆栈跟踪报告。我不知道如何重现这个。我的 WPF 应用程序有相当多的组合框;鉴于下面的堆栈跟踪,我不确定如何确定哪个 ComboBox 失败。还有其他人看到这个吗?你能从这个堆栈跟踪中解释发生了什么吗?有什么想法吗?
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Controls.ComboBox.CoerceIsSelectionBoxHighlighted(Object o, Object value)
at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.CoerceValue(DependencyProperty dp)
at System.Windows.Controls.ComboBox.OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FocusWithinProperty.FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, Boolean oldValue)
at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
at System.Windows.ReverseInheritProperty.OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, IList`1 otherOrigins, DeferredElementTreeState& oldTreeState, Action`2 originChangedAction)
at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
at System.Windows.Input.KeyboardDevice.PostProcessInput(Object sender, ProcessInputEventArgs e)
at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
at System.Windows.Interop.HwndKeyboardInputProvider.PossiblyDeactivate(IntPtr hwndFocus)
at System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr hwnd, WindowMessage message, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
最佳答案
这是代码 (.NET 4.5.2)。 o
不是 ComboBox
或 HighlightedElement
为 null。
就个人而言,我的第一步是分发 PDB,以便您可以在堆栈跟踪中获取行号。
private static object CoerceIsSelectionBoxHighlighted(object o, object value)
{
ComboBox comboBox = (ComboBox)o;
return (!comboBox.IsDropDownOpen && comboBox.IsKeyboardFocusWithin) ||
(comboBox.HighlightedInfo != null && comboBox.HighlightedElement.Content == comboBox._clonedElement);
}
private ComboBoxItem HighlightedElement
{
get { return (_highlightedInfo == null) ? null : _highlightedInfo.Container as ComboBoxItem; }
}
关于c# - ComboBox 强制崩溃(不是我的代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29306589/