Copied to clipboard

Flag this post as spam?

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


  • Nick Beaugié 28 posts 80 karma points
    May 14, 2017 @ 16:33
    Nick Beaugié
    0

    umbraco.library.NiceUrl not working after upgrade to 7.6.1

    I've upgraded my installation from 7.5.13 to 7.6.1.

    I'm surprised to see that this line now throws an error:

    @umbraco.library.NiceUrl(CurrentPage.straplineLink)
    

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'umbraco.library.NiceUrl(int)' has some invalid arguments

    If I try it with a hard-coded int, it works as expected:

    @umbraco.library.NiceUrl(1069)
    

    And if I output this, it outputs the correct node ID (1069):

    @CurrentPage.straplineLink
    

    So, I have two questions:

    1. How can I get this to work? (I've tried @umbraco.library.NiceUrl(int.Parse(CurrentPage.straplineLink)) but it doesn't work because it's not actually a string.
    2. Why would this stop working due to a minor upgrade?
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 14, 2017 @ 19:27
    Alex Skrypnyk
    1

    Hi Nick

    Try this code:

    Umbraco.NiceUrl(Umbraco.AssignedContentItem.GetPropertyValue<int>("straplineLink"))
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 14, 2017 @ 19:28
    Alex Skrypnyk
    1

    Upgrade from 7.5.13 to 7.6.1 isn't minor, there are a lot of changes and few breaking changes - https://our.umbraco.org/documentation/getting-started/setup/upgrading/760-breaking-changes

    Thanks,

    Alex

  • Nick Beaugié 28 posts 80 karma points
    May 15, 2017 @ 18:47
    Nick Beaugié
    1

    Thanks so much for this, Alex! I was indeed naive to think that there were no breaking changes.

    I wrote the code some time back, so I guess I must be doing quite a few things that are now deprecated.

    I also have this code later on. I have a list of items, some of which have an Image property set (for a media gallery item).

    @var profileItems = CurrentPage.Children();
    @foreach (var item in profileItems)
    {
         var isItemImagePresent = !string.IsNullOrWhiteSpace(item.profileItemImage);
         var descriptionClass = isItemImagePresent ? "col-lg-10" : "col-lg-12";
         // some more code
    }
    

    And this gives the very similar error:

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'string.IsNullOrWhiteSpace(string)' has some invalid arguments

    Any idea what the best practice way of dealing with this is?

    Note that I adapted this code from the "TXT" starter template. There, they used an image uploader for the image property. I allow images to be optional in news items. I later changed to use a Media Item instead (because I didn't like the way that an uploaded image is inaccessible after a user changes it and preferred images to be in the Media Section). Checking for string.IsNullOrWhiteSpace worked OK before 7.6.1.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 15, 2017 @ 20:23
    Alex Skrypnyk
    0

    You are welcome, Nick. A lot of people realized that they need to change razor code little bit after latest upgrade.

    Is "Property Value Converters" enabled in your solution?

    It's important for fixing this issue if it's disabled this code should work:

    var isItemImagePresent = !string.IsNullOrWhiteSpace(item.profileItemImage.ToString());
    

    Just add .ToString()

    Thanks,

    Alex

  • Nick Beaugié 28 posts 80 karma points
    May 15, 2017 @ 21:07
    Nick Beaugié
    1

    Thanks so much Alex. I've now got the local version of my site working.

    I'll test it properly before updating on Prod. Here's the site if you are interested: http://www.thesquad.org.uk

    To answer your question - no, I don't have Property Value Converters. I've just Googled and wonder if I should. This site is just something I maintain in my spare time and I don't have a lot of time to do proper Umbraco stuff. But I think I will make time to check this out.

Please Sign in or register to post replies

Write your reply to:

Draft