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.
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.
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.
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:
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-detectedbut 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?
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
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 typeIPublishedContent
.is working on a reply...