System.Text.Json.JsonException - When enabling Lazy Loading in EF Core
Hi,
Attachment: dump_4a6e7452.zip
I have a grid that was working ok, until I enabled Lazy Loading in EF Core v. 5.02.
I tried adding ActionFailureHandler, but this was not called.
SyncFusion.Blazor version: 18.3.0.53
Attachment: dump_4a6e7452.zip
SIGN IN To post a reply.
14 Replies
1 reply marked as answer
VN
Vignesh Natarajan
Syncfusion Team
January 14, 2021 07:44 AM UTC
Hi Michael,
Thanks for contacting Syncfusion support.
Query: “I have a grid that was working ok, until I enabled Lazy Loading in EF Core v. 5.02. I tried adding ActionFailureHandler, but this was not called.”
We have analyzed the reported query by preparing a sample with LazyLoading EF v5.0 and we are not able to reproduce the reported issue at our end. Kindly download the sample from below
Note:
1. kindly change the connection string of NorthWnd database in AppSettings.json file based on NorthWnd.MDF file in App_Data folder.
2. we have upgraded our Syncfusion.Blazor components to Dot Net 5.0 in our 18.4.0.30. So kindly ensure that you have referred latest version Syncfusion.Blazor Nuget or alter than 18.4.0.30
After referring the sample, if you are still facing the issue. Kindly get back to us if with following details.
- Share the Grid code example.
- Are you facing any exception in browser console. If yes, share the screenshot of the error.
- Kindly confirm whether the data is being returned from your database.
- Share your Nuget (Syncfusion.Blazor) package version
- Are you facing the reported issue during the initial rendering or during a certain action.
- Share the issue reproducible sample or try to reproduce the reported issue in provided sample.
Above requested details will be helpful for us to validate the reported query at our end and provide solution as early as possible.
Regards,
Vignesh Natarajan
MØ
Michael Østerberg
January 14, 2021 03:48 PM UTC
Hm. Please put this on hold.
I've gotten the same error today, without using Lazy Loading. So that problem is something else. I'll try and debug some more.
RS
Renjith Singh Rajendran
Syncfusion Team
January 15, 2021 05:38 AM UTC
Hi Michael,
Thanks for your update.
We will wait to hear from you. Please check this case from your side. And if you still need further assistance, then kindly get back to us with the requested details for better assistance.
Regards,
Renjith R
MØ
Michael Østerberg
January 15, 2021 10:08 AM UTC
I've done some testing and I can now re-create the error.
Attachment: New_folder_58c004f4.zip
I'm just clicking on two different buttons to navigate to two other components in my main page (ServiceAgreementList) and invoking the Cancel (Back) from these razor components. I DON'T change any data.
On the return from these components I do a reload of the List just in case the a ServiceAgreement was added or deleted. The reload is via EF Core.
Within 4-6 razor component calls + returns the same dump occurs:
Error: System.Text.Json.JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
at System.Text.Json.ThrowHelper.ThrowJsonException_SerializerCycleDetected(Int32 maxDepth)
I've added the ActionFailureHandler but this doesn't get called.
See razor components and dump in attached zip
SyncFusion Nuget (18.4.0.34)
EF Core 5.0.2
C# .Net 5.0
Attachment: New_folder_58c004f4.zip
RS
Renjith Singh Rajendran
Syncfusion Team
January 18, 2021 12:58 PM UTC
Hi Michael,
Thanks for sharing the details.
We upgraded the EF to 5.0.2 in the sample from our previous update, and tried reproduce the reported exception by navigating the pages. But we could not face any exception on navigation in the sample from our side. Please download and refer the video demo and sample for your reference.
Video demo : https://www.syncfusion.com/downloads/support/directtrac/general/ze/lazyloading161599332
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/Gridlazyloading1897686110
Note : Ensure to change the connection string in appsettings.json file in the above sample before running the application.
Please try this scenario by clearing the nuget and browser cache from your side. And if you are still facing difficulties, then the following details would be helpful for us to validate on this and provide you a suggestion as early as possible.
- Share with us a simple issue reproducing sample demo. This would be helpful for us to validate the problem based on your scenario.
- Share with us a video demo showing the replication procedure of the problem you are facing.
- Share with us the exact scenario and proper replication procedure to reproduce the problem.
- Or if possible, reproduce the reported problem with the above sample and share with us for further analysis.
The provided information will help us analyze the problem, and provide you a solution as early as possible.
Regards,
Renjith R
MØ
Michael Østerberg
January 19, 2021 08:58 AM UTC
Hi,
I've been googling a bit and I think the issue/problem is cyclic references in my DataModel.
I've created the DataModel as EF Core Code First and it does contain cyclic references.
I found this stackoverflow:
https://stackoverflow.com/questions/59199593/net-core-3-0-possible-object-cycle-was-detected-which-is-not-supported
which mentions this option
services.AddControllersWithViews() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore );
but the Newtonsoft.Json is an integral part of Syncfucion. Can I change this option?
RS
Renjith Singh Rajendran
Syncfusion Team
January 27, 2021 12:59 PM UTC
Hi Michael,
As you are using EF Code first approach, we suggest you to try setting [System.Text.Json.Serialization.JsonIgnore] for the fields with cyclic references in your DataModel.
|
public class Employee
{
...
[System.Text.Json.Serialization.JsonIgnore]
public virtual Order Order { get; set; }
}
public class Order
{
...
[System.Text.Json.Serialization.JsonIgnore]
public virtual Employee Emp { get; set; }
}
|
Please try the above suggestion from your side and get back to us if you need further assistance.
Regards,
Renjith R
Marked as answer
MØ
Michael Østerberg
January 27, 2021 02:12 PM UTC
Thank you.
I'll try that.
RS
Renjith Singh Rajendran
Syncfusion Team
January 28, 2021 04:54 AM UTC
Hi Michael,
Please check the suggestion from your side, and get back to us if you need further assistance.
Regards,
Renjith R
FR
Francis
March 7, 2021 04:36 PM UTC
I was having the same issue and this fixed my issue. Thanks.
RS
Renjith Singh Rajendran
Syncfusion Team
March 8, 2021 05:32 AM UTC
Hi Francis,
We are glad to hear that the suggestion helped you in achieving your requirement.
Please get back to us if you need further assistance.
Regards,
Renjith R
PI
POL IT
December 4, 2022 02:22 AM UTC
This still seems to be an issue to people who don't want to decorate their models, I would recommend to the syncfusion team to allow JsonSerializerOptions to be modified before use, so we choose how our data gets serialized.
NP
Naveen Palanivel
Syncfusion Team
December 8, 2022 01:55 AM UTC
Hi Pol,
We are currently Validating the reported query at our end and we will update the further details shortly. Until then we appreciate your patience.
Regards,
Naveen Palanivel
NP
Naveen Palanivel
Syncfusion Team
December 14, 2022 02:26 AM UTC
Hi PoL,
We have analyzed your query, Currently we don't have support for without decorate their models to allow JsonSerializerOptions
Please let us know if you have any concerns.
Regards,
Naveen Palanivel
SIGN IN To post a reply.
- 14 Replies
- 6 Participants
- Marked answer
-
MØ Michael Østerberg
- Jan 13, 2021 10:59 AM UTC
- Dec 14, 2022 02:26 AM UTC