Home Forums WPF controls Xceed DataGrid for WPF Help with exception in Expression Blend & at run time.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25494 |

    I’ve got a usercontrol that shows an exception (“Object reference not set to an instance of an object”) at design time in Blend whenever I add a DataGridCollectionViewSource. When I run, The grid show up very briefly with what appears to be the correct data & then crashes because the same exception seen at design time is being thrown at run time. The stack trace from the exception is as follows:

    at Xceed.Wpf.DataGrid.DataGridCollectionViewGroup.GetRawItemAtGlobalSortedIndex(Int32 index)
    at Xceed.Wpf.DataGrid.DataGridCollectionView.SaveCurrentBeforeReset(RawItem& oldCurrentRawItem, Int32& oldCurrentPosition)
    at Xceed.Wpf.DataGrid.DataGridCollectionView.ForceRefresh(Boolean sendResetNotification, Boolean initialLoad)
    at Xceed.Wpf.DataGrid.DataGridCollectionView.DeferredOperationManager.Process(Boolean processAll)
    at Xceed.Wpf.DataGrid.DataGridCollectionView.DeferredOperationManager.Dispatched_Process(Object e)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
    at System.Windows.Threading.DispatcherOperation.InvokeImpl()
    at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
    at System.Threading.ExecutionContext.runTryCode(Object userData)
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Windows.Threading.DispatcherOperation.Invoke()
    at System.Windows.Threading.Dispatcher.ProcessQueue()
    at System.Windows.Threading.Dispatcher.WndProcHook(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, Boolean isSingleParameter)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
    at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
    at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
    at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
    at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
    at System.Windows.Threading.Dispatcher.Run()
    at System.Windows.Application.RunInternal(Window window)
    at System.Windows.Application.Run(Window window)
    at System.Windows.Application.Run()

    I have a separate test project that I used to create my first sample app using the grid & had no problem. The difference between the 2 projects is that the successful app uses an ObjectDataProvider as the source for the DataGridCollectionViewSource and the unsuccessful app uses an XmlDataProvider.

    This all happens when by XmlDataProvider and DataGridCollectionViewSource look like this:

    <XmlDataProvider x:Key=”WidgetDataProvider”
    Source=”C:\TestData\Widgets.xml”/>

    <xcdg:DataGridCollectionViewSource x:Key=”WidgetViewSource”
    Source=”{StaticResource WidgetDataProvider}”/>

    If I change this so that I provide an XPath (XPath=”//Widget”) for the XmlDataProvider, then the app will start and show the correct data, but will then crash when I try to sort by clicking the column header or group by dragging a column header to the top. I have a single column for the grid that is manually defined.

    <xcdg:DataGridControl Grid.Row=”1″
    x:Name=”DataGrid”
    HorizontalAlignment=”Stretch”
    VerticalAlignment=”Stretch”
    AutoCreateColumns=”false”
    ItemsSource=”{Binding Source={StaticResource WidgetViewSource}}”>

    <xcdg:DataGridControl.Columns>

    <xcdg:Column Title=”Name”
    FieldName=”Name”
    Width=”200″
    DisplayMemberBinding=”{Binding XPath=@Name}”/>

    </xcdg:DataGridControl.Columns>

    </xcdg:DataGridControl>

    Regardless of whether I provide the XPath to the XmlDataProvider, I still get the “Object reference not set to an instance of an object” design time exception reported for line 1 of the user control. If I remove the Source attribute for the DataGridCollectionViewSource, the exception goes away. Is there something about setting the source to an XmlDataProvider here that I don’t understand?

    TIA

    Imported from legacy forums. Posted by m_d_blake (had 3865 views)

    User (Old forums)
    Member
    Post count: 23064

    After more experimentation, it doesn’t matter what project I’m working in (so I can ignore all other differences), this always generates the design time exception (although I can still build and run so I can get the runtime exception as well 🙂 )

    <XmlDataProvider x:Key=”WidgetDataProvider”
    Source=”C:\TestData\Widgets.xml”
    XPath=”//Widget”/>

    <xcdg:DataGridCollectionViewSource x:Key=”WidgetViewSource”
    Source=”{StaticResource WidgetDataProvider}”/>

    It is definitely the use of the XmlDataProvider. Any ideas what I’m missing?

    Imported from legacy forums. Posted by m_d_blake (had 416 views)

    User (Old forums)
    Member
    Post count: 23064

    More info:

    If I create a CollectionViewSource, set it’s source to the same XmlDataProvider, I don’t get the crash at runtime when sorting via the column headers.

    <CollectionViewSource x:Key=”ColViewSource” Source=”{StaticResource WidgetDataProvider}”/>

    Imported from legacy forums. Posted by m_d_blake (had 379 views)

    User (Old forums)
    Member
    Post count: 23064

    I am getting the same type of error.

    In my scenario, I have a grid on page in an XBAP and the data loads and displays fine. However, when I try to view the same data from a dialog window (same grid, data provider and collection view), I get the same error as referenced in the original post.

    If I wrap the the ShowDialog() method in a try catch, the data displays fine:

    try
    {
    window.ShowDialog();
    }
    catch(NullReferenceException x)
    { }

    Makes no sense to me and I was hoping that a solution or more elegant workaround had been found.

    Imported from legacy forums. Posted by Kennie (had 1042 views)

    User (Old forums)
    Member
    Post count: 23064

    Has this issue been resolved or is the cause of it known?

    I have the same problem with version 1.3 of the grid published 18-12-2007. Installer version is 12.0.0.58851

    Imported from legacy forums. Posted by Jesper (had 4557 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.