Copied to clipboard

Flag this post as spam?

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


  • Carlos Gómez 25 posts 55 karma points
    Dec 12, 2020 @ 04:28
    Carlos Gómez
    0

    IPublishedContent showing null object reference error using Vorto

    I have a weird question... there is a site that has been running for 2 or 3 years without any problem. It is implemented in 7.6.5, but suddenly some pages started to show the null reference exception.

    I have this code:

    @Model.Content.GetVortoValue("salaPrensaImagenEncabezado")
    

    it returns this: Umbraco.Core.Udi[]

    It doesn't show any exception.

    But when I change to this:

    @Model.Content.GetVortoValue<IPublishedContent>("salaPrensaImagenEncabezado")
    

    or

    @Model.Content.GetVortoValue<IPublishedContent>("salaPrensaImagenEncabezado").Url
    

    note: spaces before and after IPulblishedContent are intentionally to be shown. If I remove those spaces the post question hides the casting.

    it shows the null reference exception.

    It was working prefectly. This property "salaPrensaImagenEncabezado" actually has value.

    These make no difference:

    <EnablePropertyValueConverters>true</EnablePropertyValueConverters>
    

    or <EnablePropertyValueConverters>false</EnablePropertyValueConverters>

    Error seems to be adding the IPublishedContent . Do I need an "using" or something on the top of the file? I have this heading the file:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Our.Umbraco.Vorto.Extensions;
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    

    Thank you very much in advance.

  • Carlos Gómez 25 posts 55 karma points
    Dec 15, 2020 @ 04:12
    Carlos Gómez
    0

    I found the way to fix this:

    @((Model.Content.GetVortoValue<IEnumerable<IPublishedContent>>("salaPrensaImagenEncabezado").ElementAt(0)).Url)
    

    Can somebody explain to me why the previous code worked since 2017 and suddenly now, it is not working anymore?

    Old code, working until few days ago:

    @Model.Content.GetVortoValue<IPublishedContent>("salaPrensaImagenEncabezado").Url
    

    Please!!

Please Sign in or register to post replies

Write your reply to:

Draft