Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

1
Vote
Hi,  

I have a possibly unusual edge-case where I am coming up against an error using Adaptors.JsonAdaptor in EjsDataManager for an EjsGrid.  

I believe that the issue relates to the way that I have referenced the db context in my POCO.  Won't go into the full reasons for doing that here, but the short version is that I normally don't need the reference properties, but when I do, I initialise the POCO with a DbContext.  I suspect this is causing problems for your code when you try and serialise the POCO.

I've tried to pull out the relevant bits of code from a fairly large project as below.  

(I note that if I don't explicitly call out the 
JsonAdaptor
and let the control just use the default BlazorAdaptor, I don't get the problem)

As far as I can see from stepping through the code, the following occurs:
  1. Component is called and initialised
  2. The datasource is retrieved from the service class and is applied to the DataSourceJSON property of the code behind
  3. As soon as the code returns to the component and @DataSourceJSON is applied to the Json property of the DataManager, I get the error
    Error: System.AggregateException: One or more errors occurred. (Self referencing loop detected for property 'db' with type 'Model.Context.ModelDbContext'. Path '[0].db.AddresseeTypes[0]' 
    (full detail shown in the stack trace following)

Looking at the stack trace, it looks like the grid control is trying to serialise the datasource and is getting some sort of loop when it gets to the reference properties of the POCO.  Note that the POCO is not the same one that the grid i based upon - it is the first one in my db context.  If I remove that class from my Db Context, it just goes to the next one.

I found a possible reference on SO that gave some possible options to resolve this error, but I was not able to get any of them to work.  

The Component code is as follows (you'll notice that I have subclassed the EJSGrid, but I have tested and get the same error without the subclass)

ComponentCode.PNG


Service Class as follows (this is called from Code Behind to initialise @DataSourceJSON:

Empty

Empty


Stack Trace is:

[2020-02-25T23:39:57.335Z] Error: System.AggregateException: One or more errors occurred. (Self referencing loop detected for property 'db' with type 'Model.Context.ModelDbContext'. Path '[0].db.AddresseeTypes[0]'.)

 ---> Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'db' with type 'Model.Context.ModelDbContext'. Path '[0].db.AddresseeTypes[0]'.

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, 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.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, 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.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, 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.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, 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.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, 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.JsonSerializer.Serialize(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 Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting)

   at Syncfusion.EJ2.Blazor.DataSourceTypeConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, 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.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, 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.JsonSerializer.Serialize(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.serialiazeBindableProp(Dictionary`2 bindableProp)

   at Syncfusion.EJ2.Blazor.BaseComponent.OnAfterRenderAsync(Boolean firstRender)

   at Syncfusion.EJ2.Blazor.Grids.EjsGrid`1.OnHybridAfterRender(Boolean firstRender)

   at Syncfusion.EJ2.Blazor.Grids.EjsGrid`1.OnAfterRenderAsync(Boolean firstRender)

   --- End of inner exception stack trace ---



POCO Class referenced in Stack Trace is as follows: (abridged)

 
public partial class Addressee
    {
        private ModelDbContext _db;
        public ModelDbContext db
        {
		get => _db
		set { _db = value; 
	}
        public Addressee()     {}
        public Addressee(ModelDbContext db) { _db = db; }
        public Guid GUID { get; set; } = new Guid();
        public int ID { get; set; }
        public Guid? ProjectGUID_FK { get; set; }
        private Project _project;
        public virtual Project Project()
        {
            if (_project == null)
            {
                _project = db.Projects.FirstOrDefault(x => x.GUID == this.ProjectGUID_FK);
            }

            if (_project?.GUID != this.ProjectGUID_FK)             {                 _project = db.Projects.FirstOrDefault(x => x.GUID == this.ProjectGUID_FK);             }             return _project;         }     }