Xceed PropertyGrid с System.Windows.Media.Color[] вызывает NullReferenceException

У меня есть объект, который я пытаюсь использовать с PropertyGrid, и он генерирует исключение NullReferenceException при попытке доступа к свойству Color[].

Трассировка стека выглядит так:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Xceed.Wpf.Toolkit.CollectionControlDialog.Clone(Object source) in C:\Users\brian\Documents\Visual Studio 2015\Projects\FevDnDTester\ExtendedWPFToolkitSolution\Src\Xceed.Wpf.Toolkit\CollectionControl\Implementation\CollectionControlDialog.xaml.cs:line 168
   at Xceed.Wpf.Toolkit.CollectionControlDialog.OnSourceInitialized(EventArgs e) in C:\Users\brian\Documents\Visual Studio 2015\Projects\FevDnDTester\ExtendedWPFToolkitSolution\Src\Xceed.Wpf.Toolkit\CollectionControl\Implementation\CollectionControlDialog.xaml.cs:line 137
   at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
   at System.Windows.Window.CreateSourceWindowDuringShow()
   at System.Windows.Window.SafeCreateWindowDuringShow()
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at System.Windows.Window.Show()
   at System.Windows.Window.ShowDialog()
   at Xceed.Wpf.Toolkit.CollectionControlButton.CollectionControlButton_Click(Object sender, RoutedEventArgs e) in C:\Users\brian\Documents\Visual Studio 2015\Projects\FevDnDTester\ExtendedWPFToolkitSolution\Src\Xceed.Wpf.Toolkit\CollectionControl\Implementation\CollectionControlButton.cs:line 124
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   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.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, 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)

Как видите, нет ничего, связанного с моим собственным кодом, так что это должно быть довольно распространенной ошибкой. Похоже, он пытается клонировать мой массив объектов Color и терпит неудачу, но массив и ни один из объектов внутри не являются нулевыми.

есть идеи?


person brianestey    schedule 30.11.2016    source источник


Ответы (1)


Это ошибка в классе CollectionControlDialog.

В методе Clone() они получают тип предоставленного элемента коллекции, а затем пытаются вызвать конструктор по умолчанию этого типа. Я полагаю, они хотят создать глубокую копию каждого элемента коллекции.

Но очевидно, что у struct Color нет конструктора по умолчанию (как метода), который можно было бы получить с помощью отражения. (Конструктор без параметров по умолчанию, который вы могли бы использовать в struct, на самом деле не конструктор, а инструкция IL для среды выполнения, как создать экземпляр struct по умолчанию).

Вот почему метод GetConstructor() возвращает значение null, а попытка вызвать метод для null выдает NullReferenceException, которое вы видите.

Вы можете перечислить ошибку или исправить ее самостоятельно и зафиксировать в репозитории Xceed.

В настоящее время эта ошибка не позволяет вам использовать CollectionControlDialog с такими объектами, которые не имеют конструктора без параметров по умолчанию (например, structs или некоторые classes).

person dymanoid    schedule 01.12.2016
comment
Отличный ответ! Я сообщил об ошибке в их поддержку, и она будет исправлена ​​в версии 3.3. Тем временем я обошел его в локальной копии. - person brianestey; 02.12.2016