Export is useless... NullReferenceException

2 posts, 0 answers
  1. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 10 Dec 2010 Link to this post

    Hello,
    Once again I have a problem with exporting data from my grid.

    System.NullReferenceException was caught
      Message=La référence d'objet n'est pas définie à une instance d'un objet.
      StackTrace:
           à Telerik.Windows.Data.TypeExtensions.DefaultValue(Type type)
           à Telerik.Windows.Data.Expressions.ExpressionFactory.DefaltValueExpression(Type type)
           à Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Type memberType)
           à Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Type memberType, Boolean liftMemberAccessToNull)
           à Telerik.Windows.Data.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpressionOverride()
           à Telerik.Windows.Data.Expressions.MemberAccessExpressionBuilderBase.CreateMemberAccessExpression()
           à Telerik.Windows.Data.Expressions.MemberAccessExpressionBuilderBase.CreateLambdaExpression()
           à Telerik.Windows.Data.BindingToExpressionExtensions.CreateMemberAccessLambdaExpression(Binding binding, Type objectType, Type memberType)
           à Telerik.Windows.Data.BindingToExpressionExtensions.CreateUntypedMemberAccessFunc(Binding binding, Type objectType, Type memberType)
           à Telerik.Windows.Data.BindingToExpressionExtensions.CreateMemberAccessFunc(Binding binding, String stringFormat, Type objectType, Type memberType)
           à Telerik.Windows.Data.BindingToExpressionExtensions.CreateMemberAccessFunc(Binding binding, Type objectType, Type memberType)
           à Telerik.Windows.Controls.GridViewBoundColumnBase.InitializeMemberAccessFunc()
           à Telerik.Windows.Controls.GridViewBoundColumnBase.get_MemberAccessFunc()
           à Telerik.Windows.Controls.GridViewBoundColumnBase.GetCellContent(Object item)
           à Telerik.Windows.Controls.GridViewExportWriter.RenderDataCells(Object item)
           à Telerik.Windows.Controls.GridViewExportWriter.RenderDataRows(IEnumerable items)
           à Telerik.Windows.Controls.GridViewExportWriter.Render()
           à Telerik.Windows.Controls.GridView.GridViewDataControl.Export(Stream stream, GridViewExportOptions options)
           à SoPratic.SL.Views.Command.btnExport_Click(Object sender, RoutedEventArgs e)
      InnerException:

    When I say that the export is useless it's because code like this one should be rock solid and despite what happens, never crash. Never ever...
    Also, the exception does not help at all to identify what is happening.

    All I was able to do is the following:
            private void grdBeneficiaire_ElementExporting(object sender, GridViewElementExportingEventArgs e)
            {
                Debug.WriteLine(String.Format("ElementExporting: {0}{1}.", e.Element, e.Value));
            }
     
            private void grdBeneficiaire_Exporting(object sender, GridViewExportEventArgs e)
            {
                Debug.WriteLine(String.Format("Exporting: {0}{1}.", e.Element, e.Value));
               }

    To dump my data and see where you code crashed...

    I know that other cells are empty, null or read only, so I cannot see why it's not working.

    Here is the code for the column involved in the crash... I even though I can provide a default value but it does not help...

                    <telerik:RadGridView Name="grdBeneficiaire" Margin="0,5" IsReadOnly="False" AutoGenerateColumns="False" ShowInsertRow="False"
                                     ItemsSource="{Binding ElementName=customerDomainDataSource, Path=Data}" ShowGroupFooters="True" ShowColumnFooters="True"
                                     Exporting="grdBeneficiaire_Exporting" Deleting="grdBeneficiaire_Deleting" CanUserInsertRows="False" CanUserDeleteRows="False" ElementExporting="grdBeneficiaire_ElementExporting">
                        <i:Interaction.Behaviors>
                            <local:EmptyDataTemplateBehavior>
                                <local:EmptyDataTemplateBehavior.EmptyDataTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="Votre commande est vide." Foreground="Gray" HorizontalAlignment="Center"  VerticalAlignment="Center" />
                                    </DataTemplate>
                                </local:EmptyDataTemplateBehavior.EmptyDataTemplate>
                            </local:EmptyDataTemplateBehavior>
                        </i:Interaction.Behaviors>
    ...
                            <telerik:GridViewDataColumn Header="Mis à jour" DataMemberBinding="{Binding ModifiedOn, TargetNullValue='Jamais', FallbackValue='Erreur'}" UniqueName="ModifiedOn" IsReadOnly="True" />
    ...
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>

    Do you mind:
    - Give specific details in teh exception about what happened? Where you unable to read the data? Write the data? What was the column and row and cell involved... Something more usefull then NullReferenceException
    - Provide a callback to let us handle the situation? Give me access to all your input parameter and let me modify them
    - Never crash if I don't want you to. Just ignore the cell, put it out empty and move on to the next...

    I also threat the export as useless as it cannot be trusted. For 3 month I reported a bug that you corrected in handling null values. My code then worked. And today it's not working anymore (I did not use the code for month because it was crashing at the time and I'm just trying to make use of it again).

    Voila,
    Any hints about what I can do ?
    Thank a lot in advance,
    John.
  2. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 10 Dec 2010 Link to this post

    Ok, I found the problem...

    The problem was that my column was bound to a non existing property. Sorry. It's working...

    Nonetheless my suggestions stay valid. It should never crash whatever the reason is and we should have a callback to handle the eventual errors (maybe there is one already).

    Thank you for listening ;)

    John.

    ps: eventually it would be nice to be able to mark one's own questions as answered...
  3. DevCraft banner
Back to Top