2016-11-30 68 views
1

我有一個對象,我試圖用PropertyGrid和它嘗試訪問Color []屬性時引發NullReferenceException。Xceed PropertyGrid與System.Windows.Media.Color []拋出NullReferenceException

堆棧跟蹤看起來像:

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對象數組並失敗,但數組和內部的對象均爲null。

有什麼想法?

回答

1

這是CollectionControlDialog類中的一個錯誤。

在方法Clone()中,它們獲取提供的集合項的類型,然後嘗試調用該類型的默認構造函數。我想,他們想要創建每個收集項目的深層副本。

但顯然,一個structColor沒有默認的構造函數(作爲一種方法),它可以通過反射獲得。 (您可以在struct上使用的默認無參數構造函數實際上不是構造函數,但它是運行時如何創建struct的默認實例的IL指令)。

所以這就是爲什麼GetConstructor()方法返回null,並試圖調用一個null的方法拋出NullReferenceException你觀察。

你可以列出一個錯誤或自己修復它,並承諾到Xceed存儲庫。

目前,這個bug會阻止您能夠與不具有默認參數的構造函數這樣的對象(如struct S或一些class ES太)使用CollectionControlDialog

+0

很好的答案!我將錯誤提交給他們的支持,它將在v3.3中修復。與此同時,我在本地副本中解決了這個問題。 – brianestey

相關問題