Copied to clipboard

Flag this post as spam?

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


  • Simon 81 posts 184 karma points
    May 25, 2017 @ 09:26
    Simon
    0

    Problem with UmbracoHelper.TypedMedia under Umbraco 7.6

    Hi,

    I have an IIS cached model that uses list of content items including an image id. This model is correctly populated with the media id under 7.6 to use the new udi format.

    var image = umbracoHelper.TypedMedia(Model.Items[i].ImageUrl);
    

    So Model.Items[i].ImageUrl contains a string in the format of "umb://media/f0853da8502642afa39deaa7094c828a" as expected. However, TypedMedia throws the following exception:

    Value cannot be null. Parameter name: mediaItem
    

    Any ideas would be much appreciated.

    Thanks

    Simon

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 09:38
    Alex Skrypnyk
    0

    Hi Simon

    TypedMedia doesn't work with new formats of IDs in Umbraco. It will work in next version, but for now, you have to change your code or disable "Property Value Converters"

    Try this code:

    Udi.Parse(Model.Items[i].ImageUrl.ToString()).ToPublishedContent();
    

    Be aware that this code makes one more call to the database, so it's not the best practice.

    Thanks,

    Alex

  • Simon 81 posts 184 karma points
    May 25, 2017 @ 09:43
    Simon
    0

    Hi Alex,

    Sorry but as TypedMedia is fairly key - why did the Umbraco team release 7.6 without this support?

    If I don't want to make calls to the database what;s the best solution? You've already said what you've provided isn't best practice - what is?

    Thanks

    Simon

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 09:48
    Alex Skrypnyk
    0

    The best practice is to use "Property Value Converters" like:

    var mediaItems = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("items");
    
  • Simon 81 posts 184 karma points
    May 25, 2017 @ 10:02
    Simon
    0

    What's "items"? The string media id such as "umb://media/f0853da8502642afa39deaa7094c828a"

    Also, I can't find any reference to a ToPublishedContent() function for Udi.Parse - where did you find this?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 10:04
    Alex Skrypnyk
    0

    "items" is just example of property alias in your content.

    For "ToPublishedContent()", add please reference to "Umbraco.Web.Extensions"

    @using Umbraco.Web.Extensions
    
  • Simon 81 posts 184 karma points
    May 25, 2017 @ 10:17
    Simon
    0

    OK - found the UDI ToPublishedContent thanks

    However, the other method is fine when your model is an Umbraco DataType and not fine when it's a C# class being passed in - such as a that within a LeBlender model.

    The ability to find a media idem using a UDI is - just as it did on the old integer Id's is somewhat critical - do you have any idea when this will be implemented?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 10:21
    Alex Skrypnyk
    0

    Simon, guys told that pull request is already there and it will be in nearest release - https://our.umbraco.org/forum/templates-partial-views-and-macros/85768-new-content-picker-as-macro-parameter-v761#comment-272532

  • Simon 81 posts 184 karma points
    May 25, 2017 @ 10:28
    Simon
    0

    Unfortunately, UmbracoHelper.TypedContent() still returns the original error about:

    Value cannot be null. Parameter name: mediaItem
    
  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 10:30
    Alex Skrypnyk
    0

    Did you mean ToPublishedContent()?

  • Simon 81 posts 184 karma points
    May 25, 2017 @ 10:32
    Simon
    0

    No, in the forum post you linked to it refers to using UmbracoHelper.TypedContent as the way forward. Using UmbracoHelper.TypedContent updating the TypedMedia call to TypedContent produces the original error.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 10:33
    Alex Skrypnyk
    0

    It will work in next releases. For now, we have to use 'ToPublishedContent()' or old pickers.

  • Simon 81 posts 184 karma points
    May 25, 2017 @ 10:36
    Simon
    0

    OK. Thanks for the help - will keep an eye out for the update.

    Cheers

    Simon

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 10:36
    Alex Skrypnyk
    0

    You are welcome, Simon. Have a great day!

    Cheers

    Alex

  • Simon 81 posts 184 karma points
    May 25, 2017 @ 11:20
    Simon
    0

    I know this isn't you Alex but this breaking change wasn't in the release notes for 7.6 - Umbraco can't just go about releasing updates that then don't work with well used functions that people have built into their sites. At least - not without telling them!

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 11:26
    Alex Skrypnyk
    0

    Did you upgrade some old solution to 7.6?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 25, 2017 @ 11:25
    Alex Skrypnyk
    0

    Simon, as I know there are a lot of breaking changes in 7.6 release. enter image description here

    List of breaking changes here - https://our.umbraco.org/documentation/Getting-Started/Setup/Upgrading/760-breaking-changes

    Also some warning on the release page:

  • Simon 81 posts 184 karma points
    May 25, 2017 @ 11:45
    Simon
    0

    Yes, read all that - no where does it say that the built in UmbracoHelper.TypedMedia function doesn't support looking up using the UID.

    Given this is an Umbraco provided/supported function - it's a bit poor it now doesn't work.

    As for updating from "some old solution" - it was from the last version of 7.5.?? can't remember the last version

  • David Houghton 33 posts 108 karma points
    May 25, 2017 @ 14:21
    David Houghton
    0

    Simon, youre not alone.

    Having an absolute nightmare today with Umbraco 7.6 - so far its a very poor release.

    Personally saying its in the next release isnt an answer, useful functionality that was working perfectly has been unnecessarily removed) a lot of developers will be struggling with content queries not working...

  • Simon 81 posts 184 karma points
    May 25, 2017 @ 14:23
    Simon
    0

    Good!

    Sorry - but half-done updates like this destroy Umbraco's reputation and mean updating production sites becomes a lottery.

    Fortunately, this wasn't a production site but can you imagine???

Please Sign in or register to post replies

Write your reply to:

Draft