TopNavigation throw null reference exception

Hi,

When TopNavigation section will be removed from Main page, …\ModelBuilder\Site.generated.cs will throw Null Reference Exception.

Actual

this.Value<global::Umbraco.Cms.Core.Models.Blocks.BlockListModel>(_publishedValueFallback, "topNavigation"); 

Should be

this.HasValue(“topNavigation”) ? this.Valueglobal::Umbraco.Cms.Core.Models.Blocks.BlockListModel(_publishedValueFallback, “topNavigation”) : null;

I can fix this issue, but when ModelBuilder will be regenerated, my fix will be restored to original.

Can I apply a patch so it doesn’t get overwritten?

Best regards,

Rafał

Hi @rafalsuwald-digica

You shouldn’t modify the generated models builder files as these will get overwritten when models are generated as you have discovered. Instead, you should use C# partial classes to extend the models and provide your own customisations that you can use in your views. These will be preserved when the models are regenerated.

Hope that helps.

Justin