umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
Other
4.49k stars 2.69k forks source link

Nested Content editor inside Nested Content editor breaks webapi #11376

Closed jdpnielsen closed 3 years ago

jdpnielsen commented 3 years ago

Which exact Umbraco version are you using? For example: 8.13.1 - don't just write v8

8.15.3 (Umbraco Cloud)

Bug summary

When attempting to retrieve a document with a nested content editor inside a nested content editor, the webapi fails to serialize data correctly.

Specifics

I have been in contact with Muslim from Umbraco Support, who was able to reproduce the error.

Steps to reproduce

  1. Create a Document type (block) of name answerElement with a textfield.
  2. Create a Document type (block) of name questionElement with a nested content field which points to the answerElement block
  3. Create a Document type (Document Type) of name 'item' with a nested content field which points to questionElement.
  4. Create a content node instance of 'item' at /item
  5. Retrieve document using api: curl --location --request GET 'https://dev-pplus.euwest01.umbraco.io/umbraco/webapi/content/getbypath?path=/item'

Expected result / actual result

Expected to get the content as a JSON response.

Recieved following error:

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
  "ExceptionType": "System.InvalidOperationException",
  "StackTrace": null,
  "InnerException": {
    "Message": "An error has occurred.",
    "ExceptionMessage": "Don't know how to map ModelType with content type alias \"questionElement\".",
    "ExceptionType": "System.InvalidOperationException",
    "StackTrace": " at Umbraco.Core.Models.PublishedContent.ModelType.Map(Type type, Dictionary`2 modelTypes, Boolean dictionaryIsInvariant)\r\n at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\r\n at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\r\n at Umbraco.Core.Models.PublishedContent.ModelType.Map(Type type, Dictionary`2 modelTypes, Boolean dictionaryIsInvariant)\r\n at Umbraco.ModelsBuilder.Umbraco.PureLiveModelFactory.MapModelType(Type type)\r\n at Umbraco.Core.Models.PublishedContent.PublishedPropertyType.get_ClrType()\r\n at Ppuls.Core.Models.Property..ctor(IPublishedProperty publishedProperty)\r\n at Ppuls.Core.Models.SimpleNode.<>c.<.ctor>b__29_1(IPublishedProperty x)\r\n at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__22.MoveNext()"
  }
}
emma-hq commented 3 years ago

Hiya @jdpnielsen

Thanks for reporting this. I can see that you're using cloud but will check to see if I'm able to recreate on the CMS. If not, I'll transfer to the cloud issue tracker.

Emma

emma-hq commented 3 years ago

Heya @jdpnielsen

We've taken a look at this and we're not able to reproduce. It seems that the issue is with the custom code rather than it being a bug. In cases like this, we recommend that you go over to the friendly forum at our.umbraco.com, post and see if there's anyone who can work through the problem with you.

Emma