umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.42k stars 2.67k forks source link

Nested content not rendering correctly when only one document-type is configured #6358

Closed rensknoors closed 5 years ago

rensknoors commented 5 years ago

We noticed that some of our nested content data-types suddenly caused the error 'Object reference not set to an instance of an object.' when trying to get the data of the nested content. After looking into this issue we noticed that it happens when only 1 document-type is configured. When a second one is added, it works as intended.

This issue is already discussed with Umbraco Support and they also seem to think that this is probably a bug.

Reproduction

Bug summary

Nested content doesn't render correctly when only 1 document-type is configured.

Specifics

Version: 8.1.4 Deploy: 3.1.1

Data-type configuration: image

Code used to render the nested content:

// Nested content has alias "statistics"
var statistics = Model.Value<IEnumerable<IPublishedElement>>("statistics");
foreach (var statistic in statistics)
{
  ...
}

Steps to reproduce

Expected result

I expect to be able to loop through the nested content data-type and render everything.

Actual result

I get an error and am not able to render the data inside the nested content image

Workaround

Adding a second document-type to the nested content fixes the rendering. image

nul800sebastiaan commented 5 years ago

Interesting but unfortunately I can't reproduce this in a clean 8.1.4 install.

image

image

No null ref errors when doing this. I must assume it's some configuration problem, custom propertyvalueconverters or something else, not sure.

If you can get more steps to repro then we're all ears.

martindotcontrol commented 5 years ago

@nul800sebastiaan in the end we where able to figure out what the issue was. It's important that the setting 'is an element type' is enabled when using in compositions on nested content. The null reference error was there because the modelsbuilder was unable to build.

image

Shouldn't the backoffice give a warning in cases like these (when editing the document types)?

alexserdyuk commented 4 years ago

The same problem occurs when migrating nested content from Umbraco 7.x to Umbraco 8. There is no 'Is an Element type' property in Umbraco 7

I enabled 'Is an Element type' for all nested document types after migration, but it didn't help.

The workaround described above (adding one more document type) helps.

davit20 commented 4 years ago

hi guys here is my fix

  1. Install Umbraco.ModelsBuilder from Nuget
  2. In web.config you should have next values for Umbraco.ModelsBuilder