Copied to clipboard

Flag this post as spam?

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


  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 18, 2013 @ 12:03
    Dan Diplo
    2

    MultiUrlPickerState.Deserialize in v6.0 not working as it did in 5.5 (and a solution)

    I've just upgraded an Umbraco 6.1.6 (MVC) site from uComponents v5.5 to 6.0 - I did this using a package but I also used Nuget too (as I had a class library that referenced uComponents). The upgrade went fine. I also republished the entire site, too.

    However, I noticed that everywhere I'd used the MulitUrl picker that I was getting either no links being shown or null reference exceptions. I was using the MultiUrlPickerState.Deserialize method to deserialise the links into a collection of UrlPickerState objects. Example code was something like:

    var links = MultiUrlPickerState.Deserialize(item.GetPropertyValue<string>("links"));
    @if (links != null && links.Items.Any())
    {
        <div class="direction-links">
            @foreach (var link in links.Items)
            {
                string title = link.Title; // EXCEPTION!
                if (link.Mode == uComponents.DataTypes.UrlPicker.UrlPickerMode.URL)
                {
                    title += " website";
                }
                else if (link.Mode == uComponents.DataTypes.UrlPicker.UrlPickerMode.Media)
                {
                    title += " (file)";
                }
                
                if (link.NewWindow)
                {
                    title += " [opens in new window]";
                }
                
                <a href="@link.Url" @Umbraco.If(link.NewWindow, "target=\"_blank\"") title="@title"><span>@link.Title</span> <i class="icon-caret-right"></i></a>
            }
            
        </div>
    }
    v>
    I am now getting an "Object reference not set to an instance of an object" exception on the line when I try and reference a "link" object ie. 
    string title = link.Title;

    now throws an exception. 

    However, I have found a solution - instead of using the Deserialise method I just changed my initial code to:

    var links = item.GetPropertyValue<MultiUrlPickerState>("links");

    This works perfectly (and is also more intuitive!). 

     

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Nov 18, 2013 @ 12:09
    Lee Kelleher
    0

    Thanks Dan. Glad that you got a solution. Weird that it broke with the upgrade. As far as I recall there haven't been any amends to Multi-UrlPicker between v5.x and v6.x.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 18, 2013 @ 12:39
    Dan Diplo
    0

    Yeah, what's weird is that in some places the old cold still works and in some places it doesn't! Doesn't make much sense. I suspect it's more of an Umbraco issue than uComponents, as I've seen similar weirdness with other datatypes in the past. But hopefully if anyone encounters this it might help :)

  • Dan White 206 posts 510 karma points c-trib
    Nov 18, 2013 @ 19:08
    Dan White
    0

    I'm currently having the same issue, when using the deserialize method. It only returns one record and isn't a valid MutiUrlPickerState. Sticking with v5 for now I guess.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies