c# - ComboBox 强制崩溃(不是我的代码)

标签 c# wpf combobox stack-trace

我从客户那里得到了下面的堆栈跟踪报告。我不知道如何重现这个。我的 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 不是 ComboBoxHighlightedElement 为 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/

相关文章:

C#:从 Excel 公式中读取值

c# - 如何分离大型 ASP.NET MVC3 App?

c# - 我的 ViewModel 是否具有 Model 的属性和单独的属性?

asp.net-mvc - 在 Telerik 下拉列表 MVC 中默认显示 "Select"

c# - 如何向 ComboBox 集合添加/删除项目?

c# openfiledialog 选择多个文件,其顺序与用户选择的顺序相同

c# - ItemsControl中使用的DataTemplate中WPF组合框的默认SelectedItem无法正常工作

c# - 如何使用 OnRender 事件但仅呈现到 WPF 中的控制区域?

c# - Winforms 组合框数据绑定(bind)整个对象(无数据成员)

c# - 我可以使用 GhostscriptProcessor 返回 byte[] 吗?