We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

System.NullReferenceException: 'Object reference not set to an instance of an object when filter result is not found



I get a Error: System.NullReferenceException: 'Object reference not set to an instance of an object

when result is empty.

I use Syncfusion.Blazor.Grids.FilterType.CheckBox


@page "/klantenlijst"

@using Simar.Web.Services

@using Simar.Web.Models

@using Syncfusion.Blazor.Buttons

@using Syncfusion.Blazor.Grids

@inject INawService NawService

<h2>Klanten</h2>

<br />

<div id="ControlRegion" style="height:calc(100vh - 13rem);">


    <SfGrid ID="Grid" DataSource="@naw" @ref="Grid" AllowPaging="false" AllowFiltering="true" AllowReordering="true" AllowResizing="true" AllowPdfExport="true"

            AllowGrouping="true" AllowExcelExport="true" AllowSelection="true" EnableStickyHeader="true"

            AllowSorting="true" Toolbar="@(new List<string>() {"CsvExport","PdfExport", "ExcelExport","Search"})" Height="100%" Width="100%" EnableVirtualization="true">

        <GridEditSettings AllowAdding="false" AllowEditing="false" AllowDeleting="false" Mode="EditMode.Dialog"></GridEditSettings>

        <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.CheckBox" ShowFilterBarStatus="true" EnableCaseSensitivity="false"></GridFilterSettings>

        <GridPageSettings PageSizes="false"></GridPageSettings>

        <GridTemplates>

            <EmptyRecordTemplate>

                <span>Er zijn geen gevens on te tonen</span>

            </EmptyRecordTemplate>

        </GridTemplates>

        <GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Single"></GridSelectionSettings>

        <GridColumns>

            <GridColumn Field=@nameof(Naw.RelatieNr) HeaderText="Relatie nr." IsPrimaryKey="true" ValidationRules="@(new ValidationRules{ Required=true })" TextAlign="TextAlign.Right" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.Naam) HeaderText="Naam" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.Adres) HeaderText="Adres" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.PC) HeaderText="Postcode" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.Woonplaats) HeaderText="Woonplaats" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.EMail) HeaderText="Email" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.Telefoon3) HeaderText="Telefoon" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.Telefoon4) HeaderText="Telefoon" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.MobielNr1) HeaderText="Mobiel" Width="120"></GridColumn>

            <GridColumn Field=@nameof(Naw.MobielNr2) HeaderText="Mobiel" Width="120"></GridColumn>

        </GridColumns>

    </SfGrid>


</div>


<style>

    .ulstyle {

        margin: 0px;

        padding-left: 20px;

        display: inline-block;

    }


    .list {

        float: left;

        line-height: 20px;

        margin: 10px;

        min-width: 200px;

    }


    .btn-cls {

        margin: 0px 5px 10px 5px;

    }

</style>


@code {

    public IQueryable<Naw> naw { get; set; }


    SfGrid<Naw>? Grid;


    protected override Task OnInitializedAsync()

    {

        naw = NawService.GetNaw().Result;

        return base.OnInitializedAsync();

    }



    public void ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args)

    {

        if (args.Item.Id == "Grid_excelexport")

        {

            this.Grid?.ExportToExcelAsync();

        }

        if (args.Item.Id == "Grid_pdfexport")

        {

            this.Grid?.PdfExport();

        }

        if (args.Item.Id == "Grid_csvexport")

        {

            this.Grid?.ExportToCsvAsync();

        }

    }



}


6 Replies

VN Vignesh Natarajan Syncfusion Team October 26, 2022 12:12 PM UTC

Hi Antonio,


Greetings from Syncfusion support.


Query: “I get a Error: System.NullReferenceException: 'Object reference not set to an instance of an object when result is empty.”


We are able to reproduce the reported issue at our end while preparing the sample as per your code example. Currently, we are validating the reported issue further at our end and we need some more time to find the cause of the issue. So we will update you the further details by 28th October 2022.


Please get back to us if you have further queries.


Regards,

Vignesh Natarajan



AM Antonio Martino October 26, 2022 12:33 PM UTC

I notice that this only goes wrong with an IQueryable if I convert this to List then this doesn't happen.

Now I don't know what DataSource is doing here, otherwise I could have intervened.

I also don't know if the filtering actually uses the IQueryable Linq.

Furthermore, I use Couchbase as a database, here too there may be a reason that he handles this differently than, for example, MSSQL.



MS Monisha Saravanan Syncfusion Team October 27, 2022 02:30 PM UTC

Hi Antonio,


Thanks for the update.


We are currently validating your query at our end. We will update further details within two business days on or before 31st October, 2022.


Until then we appreciate your patience.


Regards,

Monisha



MS Monisha Saravanan Syncfusion Team November 1, 2022 03:23 PM UTC


Hi Antonio,


Thanks for the patience.


We have considered it as a bug and logged an issue  “Exception throws when filtered results are empty while using AsQueryable DataSource” for the same. Thank you for taking time to report this issue and helping us to improve our product. At Syncfusion, we are committed to fix all validated defects (subject to technological feasibility and Product Development Life Cycle) and this fix will be included in our upcoming patch release which is expected to be rolled out on or before 29th  November, 2022.


You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.       


https://www.syncfusion.com/feedback/38796/exception-throws-when-filtered-results-are-empty-while-using-asqueryable


Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization”


Until then we appreciate your patience.


Regards,

Monisha




MS Monisha Saravanan Syncfusion Team December 15, 2022 09:30 AM UTC

Hi Antonio,


Due to some unforeseen circumstances, we could not able to include the fix for the issue in our latest release. We have planned to implement this in our upcoming volume 4 release 2022.


Disclaimer
 : Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.


We will update you once the release is rolled out. Until then we appreciate your patience.





MS Monisha Saravanan Syncfusion Team December 23, 2022 09:05 AM UTC


Hi Antonio,


We are glad to announce that our Essential Studio 2022 Volume 4 Release v20.4.0.38 is rolled out and is available for download under the following link and we have included fix for the issue “Exception throws when filtered results are empty while using AsQueryable DataSourcein our volume 4 release (20.4.0.38).


https://www.syncfusion.com/forums/179561/essential-studio-2022-volume-4-main-release-v20-4-0-38-is-available-for-download


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.



Loader.
Live Chat Icon For mobile
Up arrow icon