Forms throwing a JsonSerializationException

1 Answer 928 Views
Form
Dinesh
Top achievements
Rank 1
Iron
Dinesh asked on 06 Dec 2022, 01:18 PM | edited on 07 Dec 2022, 03:23 PM

So I am trying to use forms for the first time, I have been working with grids previously, and whenever I include a form on a Razor page or partial view within a Razor page it throws the following error.

JsonSerializationException: Self referencing loop detected for property 'Module' with type 'System.Reflection.RuntimeModule'. Path 'PageContext.ActionDescriptor.HandlerMethods[0].MethodInfo.Module.Assembly.EntryPoint'.

I tested this on several projects using custom models and the identity model and got the same result.

I saw on some older posts to include the following to the AddNewtonsoftJson options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; but this did not work.

(also tried it with the recommended serialization on https://docs.telerik.com/aspnet-core/installation/json-serialization

I do have grids setup without issue.  

Any idea what could be causing this?

see the attached file for the call stack and raw exception details

Versions:
ASP.net core 6

Microsoft.AspNetCore.Mvc.NewtonsoftJson 6.0.11

Telerik.UI.for.AspNet.core 2022.3.1109

1 Answer, 1 is accepted

Sort by
1
Accepted
Mihaela
Telerik team
answered on 08 Dec 2022, 10:50 AM

Hello Dinesh,

Since we discussed the case in a support thread, I will post the solution here in case someone else faces the same issue:

Generally, when a complex model is used (which is the case with the Razor Page scenario), the Form needs to have the FormData configuration set, as stated in the Form Razor page documentation:

https://docs.telerik.com/aspnet-core/html-helpers/layout/form/razor-page

The FormData provides the data model of the Form.

PageModel:

    public class IndexModel : PageModel
    {
        [BindProperty]
        public Person Person { get; set; }

        public void OnGet()
        {
            if (Person == null)
            {
                Person = new Person();
            }
        }
    }

 

Page:

@(Html.Kendo().Form<FormException.Models.Person>()
        .Name("formExample")
        .FormData(Model.Person)
        ...
)

 


Regards, Mihaela Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Form
Asked by
Dinesh
Top achievements
Rank 1
Iron
Answers by
Mihaela
Telerik team
Share this question
or