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

Json serializer error

When I try to update the DataSource binding on the Grid I get the following error in the browser:

<EjsGrid DataSource="@ts" Toolbar="@gridToolbar">
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
    <GridEvents OnActionComplete="OnComplete" TValue="TimeSheets" />
    <GridColumns>
…..



    public void GetTimesheet()
{
        ts = db.TimeSheets.Where(a => a.CustId == CustomerID).ToList();

    }


[2019-09-26T21:21:15.251Z] Error: System.AggregateException: One or more errors occurred. (Self referencing loop detected with type 'ReserevesTest.Data.db.TimeSheets'. Path 'dataSource[0].Officer.TimeSheets'.)
 ---> Newtonsoft.Json.JsonSerializationException: Self referencing loop detected with type 'ReserevesTest.Data.db.TimeSheets'. Path 'dataSource[0].Officer.TimeSheets'.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, Formatting formatting, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings)
   at Syncfusion.EJ2.Blazor.BaseComponent.GetSerializedModel()
   at Syncfusion.EJ2.Blazor.BaseComponent.GetUpdateModel(Boolean isInit)
   at Syncfusion.EJ2.Blazor.BaseComponent.OnAfterRender(Boolean firstRender)
   at Syncfusion.EJ2.Blazor.Grids.EjsGrid`1.OnAfterRender(Boolean firstRender)
   at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleAfterRender.OnAfterRenderAsync()
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.NotifyRenderCompletedAsync()
   --- End of inner exception stack trace ---

3 Replies

VN Vignesh Natarajan Syncfusion Team September 27, 2019 09:08 AM UTC

Hi Michael,  

Greetings from Syncfusion support.  

Query: “When I try to update the DataSource binding on the Grid I get the following error in the browser 
 
We have prepared a sample as per your suggestion and code example, but we are unable to reproduce the reported at our end. We have tried to update the data on Button click and we are able to update successfully. Kindly download the sample from below.  


The reported issue may occur when model class properties are complex properties of its own parent class. Please find some general links for self-reference loop error from below  



After referring the sample and solution, if you are still facing the issue kindly get back to us with following details.  

  1. Share the full grid rendering code example.
  2. Share the details about GetTimeSheets() method along with the model class.
  3. Are you facing the reported issue during the initial rendering or while updating the dataSource property?.
  4. If possible try to reproduce the reported issue in provided sample.

Requested details will be helpful for us to validate the reported issue at our end and provide solution as soon as possible. 

Regards,
Vignesh Natarajan. 



ML Michael Lambert September 27, 2019 08:51 PM UTC

Thanks,
this worked:
[JsonIgnore] 
[IgnoreDataMember] 
public virtual ICollection<Product> Products { get; set; } 

Here is a link with really good info: https://code.msdn.microsoft.com/Loop-Reference-handling-in-caaffaf7




VN Vignesh Natarajan Syncfusion Team September 30, 2019 04:15 AM UTC

Hi Michael,  

Thanks for the update.  

We are glad to hear that your query has been resolved by our solution. And also thanks for your suggestion.  

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan. 


Loader.
Live Chat Icon For mobile
Up arrow icon