Copied to clipboard

Flag this post as spam?

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


  • Sören Deger 733 posts 2844 karma points c-trib
    Apr 07, 2022 @ 08:34
    Sören Deger
    0

    NullReferenceException with NestedContent (no Value(), but existing SourceValue())

    Hello,

    I have the same strange Issue in Umbraco v8.18.1 with NestedContent like described here:

    https://github.com/umbraco/Umbraco-CMS/issues/7364

    HasValue() returns true and the Property "SourceValue()" contains the correct JSON-String with the complete value.

    But

     item.Value<IEnumerable<IPublishedElement>>("myAlias") 
    

    returns in an NullReferenceException. The same happens if I will access the Value() property:

    var test = element.GetProperty("iconTextBoxList");
    var test2 = test.HasValue();
    var test3 = test.GetSourceValue(); // => contains the JSON-String with correct Value
    var test4 = test.Value(); // => NullReferenceException
    
    var iconTextBoxList = element.Value<IEnumerable<IPublishedElement>>( "iconTextBoxList" ); // => NullReferenceException
    

    I have already republish the content node, rebuild the examine indexes, rebuild the database cache and reload the memory cache without luck.

    Anyone knows this issue and has a solution to solve this?

    Best, Sören

  • Lars Henrik Haugeli 8 posts 81 karma points notactivated
    May 28, 2022 @ 05:13
    Lars Henrik Haugeli
    0

    Hey, I have the same issue. Found any solution or reason for this?

  • Roger Davies 3 posts 73 karma points
    Jun 21, 2023 @ 14:47
    Roger Davies
    0

    Hi all,

    Just to let you know I came across this today - a bug present in 8.18.8 (current v8 at the time of writing).

    I have a possible workaround which I'll share further down for anyone else stuck on this in the meantime!

    For me, Nested Content in Umbraco 8 generally behaves, when this bug bites it will always return null due to an error parsing the nested content data in PureLiveModelFactory.CreateModelList(...) - hence there is no way to test for it since any call to .Value(...) even without casting will result in this exception

    The full stacktrace for me looks like:

    Umbraco.ModelsBuilder.Umbraco.PureLiveModelFactory.CreateModelList(String alias) at Umbraco.Web.PropertyEditors.ValueConverters.NestedContentManyValueConverter.ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview) at Umbraco.Core.Models.PublishedContent.PublishedPropertyType.ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview) at Umbraco.Web.PublishedCache.NuCache.Property.GetValue(String culture, String segment) at Umbraco.Web.PublishedContentExtensions.Value(IPublishedContent content, String alias, String culture, String segment, Fallback fallback, Object defaultValue) at ASP.PageViewslistSectioncshtml.Execute() in \My\Project\Views\SomeView.cshtml line 123

    Workaround that worked for me!

    Since this is a bug (only) within the PureLiveModelFactory.CreateModelList(...) method you can simply change the Web.config AppSettings to use anything other than "PureLive" (I updated mine to be "AppData" since I had no particular need for any particular Models Builder type on this project - thankfully!) and the same code with the same data will work. Hopefully your project allows this.

    I've not had a chance to debug the code at the moment as I've got a few things on, but thought I'd share what I found in my case in case it's helpful.

    I suspect there can become a secnario where the parsing of data can throw an unhandled exception within the CreateModelList(...) method of the PureLive Models Factory

Please Sign in or register to post replies

Write your reply to:

Draft