This JsonSerializerOptions instance is read-only or has already been used in serialization or deserialization.

I have an SfGrid that is using an OData SfDataManager.  After editing a record and clicking the Save button, I get the error in the subject.

.Net 7 Blazor Server, Syncfusion 24.1.41.

Here is my Grid definition (except for the GridColumns).

<SfGrid @ref="Grid" TValue="Repair"
        Query="defaultQuery"
        AllowPaging="true" AllowSorting="true" AllowFiltering="true"
        EnableHover="true" AllowResizing="true"
        AllowExcelExport="true" Toolbar="@toolbar">
    <SfDataManager Url="odata/Repairs"
                   Adaptor="Adaptors.ODataV4Adaptor"
                   HttpClientInstance="@httpClient" />
    <GridPageSettings PageSizes="true" />
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.FilterBar"
                        Mode="FilterBarMode.Immediate">
        <GridFilterColumns>
            @if (customer != null)
            {
                <GridFilterColumn Field="@nameof(Repair.CustomerId)"
                                  Operator="Operator.Equal"
                                  Predicate="and"
                                  Value="@customer.CustomerId" />
            }
            @if (inventoryItem != null)
            {
                <GridFilterColumn Field="@nameof(Repair.InventoryItemId)"
                                  Operator="Operator.Equal"
                                  Predicate="and"
                                  Value="@inventoryItem.InventoryItemId" />
            }
        </GridFilterColumns>
    </GridFilterSettings>
    <GridSortSettings>
        <GridSortColumns>
            <GridSortColumn Field="@nameof(Repair.InDate)" Direction="SortDirection.Descending" />
        </GridSortColumns>
    </GridSortSettings>
    <GridEditSettings Mode="EditMode.Dialog"
                      ShowDeleteConfirmDialog="true"
                      AllowAdding="true"
                      AllowDeleting="true"
                      AllowEditing="true"
                      Dialog="@dialogSettings">
        <HeaderTemplate>Add/Edit Repair</HeaderTemplate>
    </GridEditSettings>
    <GridEvents TValue="Repair"
                OnActionFailure="ActionFailure"
                OnActionBegin="ActionBegin"
                OnToolbarClick="ToolbackClicked"
                CommandClicked="OnCommandClicked" />
    <GridColumns>
<GridColumn Field="@nameof(Repair.RepairId)"
            IsPrimaryKey="true"
            IsIdentity="true"
            Visible="false" />

Here is the stack trace.

This JsonSerializerOptions instance is read-only or has already been used in serialization or deserialization.

at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerOptionsImmutable(JsonSerializerContext context)
   at System.Text.Json.JsonSerializerOptions.ConverterList.VerifyMutable()
   at System.Text.Json.Serialization.ConfigurationList`1.Add(TItem item)
   at Syncfusion.Blazor.Data.DataUtil.CompareAndRemove(Object data, Object original, String key)
   at Syncfusion.Blazor.Data.ODataAdaptor.Update(DataManager dataManager, String keyField, Object data, String tableName, Query query, Object original, IDictionary`2 updateProperties)
   at Syncfusion.Blazor.DataManager.<Update>d__163`1.MoveNext()
   at Syncfusion.Blazor.Grids.Internal.DataGenerator`1.<GetData>d__22.MoveNext()

I put a break in the OData controller update method but it doesn't get that far.  I can't figure out what would be causing this error.  I recently converted all of my SfGrids to use the ODataV4Adapter and some grids work ok and some get this error when saving the record.  Thanks for any help you can provide.

Thanks,
Craig


12 Replies

SP Sarveswaran Palani Syncfusion Team January 9, 2024 03:40 AM UTC

Hi Craig,

Greetings from Syncfusion support.

From your query, we suspect that you’re facing exception in adding the records in the SfGrid using ODataV4Adapter. We have prepared sample based on your request in latest version but we’re unable to reproduce a reported issue at our end. We have attached sample for your reference.

If still issue reproduce, we request you to share issue reproducible runnable sample or reproduce a reported issue in the provided sample. It’ll be more helpful to further validate the query and provide precise solution ASAP from our end.

Regards,
Sarvesh


Attachment: SfGridODataV4Adaptor_d5889e4b.zip


CB Craig Boucher January 28, 2024 06:01 PM UTC

I have some more details on what is causing the error.  

I've populated the Query parameter of the SfGrid so I can "Expand" in some related tables.  

private Query defaultQuery = new Query().Expand(new List<string> { "Customer", "InventoryItem", "RepairIssue" });

If I have only one table in my list of tables to expand, then everything works great.  As soon as I add a second table, I get the error.  I tried each of the three tables by itself, and it worked.  But as soon as I added a second table to the list, I get the error. 

Thanks,
Craig



PS Prathap Senthil Syncfusion Team January 29, 2024 01:56 PM UTC

Before proceeding with reporting the problem, we require some additional clarification from your end. Please share the following details to proceed further on our end:

               1.To analyze the reported issue, could you please share a simple and reproducible sample that demonstrates the problem? This will assist us in identifying the issue more efficiently and providing a resolution.

               2.The reported issue you have faced is the breaking issue? Are you experiencing this problem after upgrading the version?
               3. If possible, kindly share your attempt to replicate the issue using the previous attached sample.

The above-requested details will be very helpful in validating the reported query on our end and providing a solution as soon as possible. Thank you for your understanding.



CB Craig Boucher January 29, 2024 03:45 PM UTC

I updated the project that was previously attached to this post so it generates the error.  The .zip was too large to attach to the post so I created a GitHub repository.

https://github.com/cvboucher/DemoFail

The errors occurs after editing an existing record before saving.

Thanks,

Craig




CB Craig Boucher February 1, 2024 03:38 PM UTC

I was just wondering if you've had a chance to look at the project showing the bug in the SyncFusion SfGrid component when using the OData SfDataManager?  Previously I included a link to the project on GitHub but I attached the project with this post for your convenience.

Thanks,
Craig


Attachment: DemoFailmaster_53c417a4.zip


PS Prathap Senthil Syncfusion Team February 2, 2024 06:41 AM UTC

Hi Craig,


Thanks for the update,

We have considered a breaking issue and logged the defect report “In Grid, when using the edit operation with the OData v4 adaptor and expanding queries, an exception is thrown. “ for the same. Thank you for taking the time to report this issue and helping us to improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and this fix will be included in our upcoming patch release.

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

https://www.syncfusion.com/feedback/50531/in-grid-when-using-the-edit-operation-with-the-odata-v4-adaptor-and-expanding


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,

Prathap S



PS Prathap Senthil Syncfusion Team February 13, 2024 02:57 PM UTC

Hi Craig,


Thanks for your patience,

We are glad to announce that, we have included the fix for the reported issue  “In Grid, when using the edit operation with the OData v4 adaptor and expanding queries, an exception is thrown.“  in our 24.2.5 release.  So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the NuGet package for latest fixes and features from below.


NuGet : https://www.nuget.org/packages/Syncfusion.Blazor.Grid

We thank you for your support and appreciate your patience in waiting for this release.


Regards,
Prathap S



CB Craig Boucher February 17, 2024 10:39 PM UTC

I upgraded to 24.2.6 and it fixed the issue, but I ran into another issue when updating a record.  All tables listed in the "Expand" are always included in the list of properties that changed (even if it was null and wasn't changed) .  If there is a related table that is nullable and it is null for the updated record, The EF/OData Patch method assigns a new empty record to that nullable property (instead of leaving it null) and tries to add that related record to the database.

Thanks,

Craig



MS Monisha Saravanan Syncfusion Team February 19, 2024 02:13 PM UTC


Hi Craig ,


We have confirmed this as an issue and logged the defect report “Patch request is incorrect while using Expand query in DataGrid with OdataV4 adaptor” for the same and this fix will be included in our upcoming patch release which is expected to be rolled out on any of our upcoming release.


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/51066/patch-request-is-incorrect-while-using-expand-query-in-datagrid


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”



Regards,

Monisha




PS Prathap Senthil Syncfusion Team February 28, 2024 04:07 AM UTC

Hi Craig ,


We are glad to announce that, we have included the fix for the issue “Patch request is incorrect while using Expand query in DataGrid with OdataV4 adaptor” in our 24.2.8 release.  So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the Nuget package for the latest fixes and features below.


Nuget: https://www.nuget.org/packages/Syncfusion.Blazor.Grid


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


Regards,

Prathap S



CB Craig Boucher March 3, 2024 11:38 PM UTC

I have upgraded the Syncfusion Nuget package to 24.2.8 but I am still getting an error.  I have a field in my table that is nullable (InventoryItemId) and also a foreign key to a related table (InventoryItem).  If I edit an existing record where this field is null and save it without making any changes, InventoryItemId is still null but there is a newly instantiated record assigned to InventoryItem and EF is trying to add this new record to the database.  Here is the record from the database before the Patch method is called in my OData controller.


BeforePatchMethodCalled.png

Here is the record after the Patch method has been called.  Note that the InventoryItemId is still null but there is a record assigned to the InventoryItem property.  The InventoryItem property should also be null.

AfterPatchMethodCalled.png

And here is the InventoryItem property expanded.  Note that it is a newly instantiated record with invalid values.  EF is trying to add this record to the database.

NewlyInstantiatedInventoryItem.png

Here is the GridColumn declaration for the InventoryItemId field.

<GridColumn Field="InventoryItem.SerialNumber"
            HeaderText="Serial Number"
            Width="@(inventoryItem == null ? "200px" : "0px")">
    <EditTemplate>
        @{
            var repair = (Repair)context;
        }
        <SfDropDownList TValue="int?"
                        TItem="InventoryItem"
                        @bind-Value="@repair.InventoryItemId"
                        Placeholder="Serial Number"
                        FloatLabelType="FloatLabelType.Always"
                        AllowFiltering="true"
                        SortOrder="Syncfusion.Blazor.DropDowns.SortOrder.Ascending"
                        FilterType="Syncfusion.Blazor.DropDowns.FilterType.StartsWith">
            <DropDownListFieldSettings Text="@nameof(InventoryItem.SerialNumber)"
                                       Value="@nameof(InventoryItem.InventoryItemId)" />
            <SfDataManager Url="odata/InventoryItems"
                           Adaptor="Adaptors.ODataV4Adaptor"
                           HttpClientInstance="@httpClient"
                           Key="@nameof(InventoryItem.InventoryItemId)" />
        </SfDropDownList>
    </EditTemplate>
</GridColumn>


Thanks,
Craig


PS Prathap Senthil Syncfusion Team March 4, 2024 11:53 AM UTC

Before proceeding with reporting the problem, we require some additional clarification from your end. Please share the following details to proceed further on our end:
               1. To analyze the reported issue, could you please share a simple and reproducible sample that demonstrates the problem? This will assist us in identifying the issue more efficiently and providing a resolution.

                2. If possible, kindly share your attempt to replicate the issue using the previous attached sample.


The above-requested details will be very helpful in validating the reported query on our end and providing a solution as soon as possible. Thank you for your understanding.


Loader.
Up arrow icon