Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • nickornotto 291 posts 653 karma points
    May 31, 2020 @ 11:43
    nickornotto
    0

    Problem serialising umbraco model because of loop referencing

    I am trying to return search results.

    The search return a list of product models which has prices with nested content property.

    I am getting a serialisation error:

    ExceptionMessage: "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'."
    ExceptionType: "System.InvalidOperationException"
    InnerException: {Message: "An error has occurred.",…}
    ExceptionMessage: "Self referencing loop detected for property 'ContentType' with type 'Umbraco.Core.Models.PublishedContent.PublishedContentType'. Path 'Data.Result.Products[0].Price.PricesNc[0].ContentType.PropertyTypes[0]'."
    ExceptionType: "Newtonsoft.Json.JsonSerializationException"
    Message: "An error has occurred.
    

    Not sure what to do with it as I need to return products with prices.

    I tried ignoring the referencing on serialisation as per Muhammad Omar advice here: https://stackoverflow.com/questions/7397207/json-net-error-self-referencing-loop-detected-for-type

    or in Global.asax.cs as per Bishoy Hanna's advice here: https://stackoverflow.com/questions/7397207/json-net-error-self-referencing-loop-detected-for-typehttps://stackoverflow.com/questions/13510204/json-net-self-referencing-loop-detected

    but it's just causing StackOverflowException - I guess the reference is still there and it's looking witout end.

    I am not sure what to do with it and how get around so I get the results serialised?

  • Ismail Mayat 4485 posts 9947 karma points MVP 2x admin c-trib
    Jun 01, 2020 @ 13:17
    Ismail Mayat
    0

    Can you show your search source code? I suspect you are using typedsearch and that is sending back list of IPublishedContent? If so then you need to transform that list of ipublihsed content to your own list of model to fix this.

    You cannot send back IPublishedContent directly from webapi in Umbraco.

    Regards

    Ismail

  • nickornotto 291 posts 653 karma points
    Jun 03, 2020 @ 05:23
    nickornotto
    0

    I tried it already as you suggested but it still failed. (I always use models)

    So in the case you explain it won't work even if I cast it to builder's model because a model always carry a property Content which is of type IPublishedContent.

Please Sign in or register to post replies

Write your reply to:

Draft