Copied to clipboard

Flag this post as spam?

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


  • Jon 47 posts 290 karma points
    Jul 18, 2016 @ 14:24
    Jon
    0

    The call is ambiguous between the following methods or properties...

    The call is ambiguous between the following methods or properties: 'Umbraco.Web.UmbracoHelper.Media(params int[])' and 'Umbraco.Web.UmbracoHelper.Media(params string[])'

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The call is ambiguous between the following methods or properties: 'Umbraco.Web.UmbracoHelper.Media(params int[])' and 'Umbraco.Web.UmbracoHelper.Media(params string[])'

    Source Error on line 38

    Line 36:        
    Line 37:        var Slide = Umbraco.Content(slideId);
    Line 38:        var ImagePath = Umbraco.Media(Slide.image).Url;
    Line 39:        var Text = Umbraco.Content(Slide.text);
    Line 40:        var Link = Umbraco.Content(Slide.linkTo);
    
  • David Peck 690 posts 1896 karma points c-trib
    Jul 18, 2016 @ 15:01
    David Peck
    0

    Not sure what the problem is, but the problem with dynamics (rather than typed) is you're never sure on the type of your properties. Using typed will mean the code gets less confused, e.g.:

    Line 37:        var Slide = Umbraco.TypedContent(slideId);
    Line 38:        var ImagePath = Umbraco.Media(Slide.GetPropertyValue<int>("image")).Url;
    Line 39:        var Text = Umbraco.Content(Slide.GetPropertyValue<int>("text"));
    Line 40:        var Link = Umbraco.Content(Slide..GetPropertyValue<int>("linkTo"));
    
  • Jon 47 posts 290 karma points
    Jul 18, 2016 @ 15:18
    Jon
    0

    Hi David

    That wasn't the problem I guess – it didn't help :-/ But THX for your time!

    It says: The call is ambiguous between the following methods or properties: 'Umbraco.Web.UmbracoHelper.Media(params int[])' and 'Umbraco.Web.UmbracoHelper.Media(params string[])'

    And it happened out of the blue – suddenly it won't get the image path. It has no problem looping all added "slides"... but an error occurs on line 38 – imagePath...

    Heres the full code...

            <div id="carousel" class="carousel slide" data-ride="carousel">
    
              <ol class="carousel-indicators hidden-xs">
    @{
        var slidesArr = CurrentPage.slides.ToString().Split(new string[] { "," }, StringSplitOptions.None);
        int countIt = 0;
    
        foreach(var slideId in slidesArr){
    
        if (countIt == 0) {
                <li data-target="#carousel" data-slide-to="0" class="active"></li>
                    } else {
                <li data-target="#carousel" data-slide-to="@countIt"></li>
                    }
            countIt++;
        }
    }
              </ol>
    
    
    <!-- Wrapper for slides -->
              <div class="carousel-inner" role="listbox">
    
    @{
        int countItem = 1;
    
        foreach(var slideId in slidesArr){
    
            var Slide = Umbraco.Content(slideId);
            var ImagePath = Umbraco.Media(Slide.image).Url;
            var Text = Umbraco.Content(Slide.text);
            var Link = Umbraco.Content(Slide.linkTo);
    
            var LinkUrl = Link.Url;
    
            if (countItem == 1) {
    
                <div class="item active"><a href="@LinkUrl">
                  <img src="@ImagePath" alt="...">
                  <div class="carousel-caption">
                    @Slide1.text
                  </div></a>
                </div>
    
                    } else {
    
            <div class="item"><a href="@LinkUrl">
                  <img src="@ImagePath" alt="...">
                  <div class="carousel-caption">
                    @Slide1.text
                  </div></a>
                </div>
    
                }
            countItem++;
        }
    
    }
    </div>
    
  • Anthony Chudley 50 posts 197 karma points
    Jul 18, 2016 @ 15:55
    Anthony Chudley
    0

    Is that a typo on the

    var Slide1 = Umbraco.Content(slideId);

    Shouldn't that be Slide?

  • Jon 47 posts 290 karma points
    Jul 18, 2016 @ 15:58
    Jon
    0

    Ooh, that was just an typo from a test... :-)

  • Anthony Chudley 50 posts 197 karma points
    Jul 18, 2016 @ 16:02
    Anthony Chudley
    0

    In that case, have you tried:

    var Slide = Umbraco.Content(slideId);
    var imagesArr = Slide.image.ToString().Split(new string[] { "," }, StringSplitOptions.None);
    var ImagePath = Umbraco.Media(imagesArr).Url;
    

    I would recommend doing a null check against the media before returning the Url as well, as otherwise you will get a YSOD if this fails.

  • Jon 47 posts 290 karma points
    Jul 18, 2016 @ 17:20
    Jon
    0

    I'm a total newbie - so Ill need a little help on the Null test :-) And it seems to be null – but it runs though all 4 slides – just empty where text, imagepath and linkto should have been...

  • Jon 47 posts 290 karma points
    Jul 18, 2016 @ 17:33
    Jon
    0

    I've just tried to change it to:

    var Slide = Umbraco.Content(slideId);
    var ImagePath = Umbraco.Media(Slide.image.ToString()).Url;
    var Text = Umbraco.Content(Slide.text.ToString());
    var Link = Umbraco.Content(Slide.linkTo.ToString());
    

    This doesn't give an error, and it runs through alle slides. But there are no content in @ImagePath, @LinkUrl, @Slide.text

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jul 18, 2016 @ 17:40
    Dennis Adolfi
    0

    Hi Jon. The problem is that the UmbracoHelper method Umbraco.Media() method excepts both an integer parameter representation of the id, as well as a string representation. You are passing in a dynamic object, therefor the call gets ambingous.

    Either parse it as an integer with Umbraco.Media(Int32.Parse(Slide.image)) or ToString() it like Umbraco.Media(Slide.image.ToString()). Off corse you need to check before the it has a value with

    if(Slide.HasValue("image"))

    Best of luck to you!! Take care!

  • Jon 47 posts 290 karma points
    Jul 18, 2016 @ 18:39
    Jon
    0

    Hi Dennis

    I've added the ToString() – and now there's no error... But it doesn't even reach the Id of the Slides... I've added Languages earlier today...could that have made any changes to this?

  • Jon 47 posts 290 karma points
    Jul 18, 2016 @ 19:34
    Jon
    0

    I've worked my way back to see where it fails. It seems that Slide never gets defined. I am not able to print @Slide – but Im able to print @SlideId.

    So my guess is that its in this line somethings wrong?

    var Slide = Umbraco.Content(slideId);
    
  • David Peck 690 posts 1896 karma points c-trib
    Jul 18, 2016 @ 21:33
    David Peck
    0

    You need to confirm what type slideId actually is. If you output @slideId.GetType() then you're looking for this to be a string or an int for your code to work.

    Depending on your installed packages and code, it might return something different.

  • Jon 47 posts 290 karma points
    Jul 19, 2016 @ 08:35
    Jon
    100

    I've just found the problem...

    It seems that even if I've publish all slides and slideholder with the common "Save & Publish" button, I still have to right click and click "publish" and select these to....

    » Publish Frontpage Sliders and all its subpages » Include unpublished child pages

    Isn't that a bug?

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jul 19, 2016 @ 10:07
    Dennis Adolfi
    0

    Hi Jon. Is it possible that you might have forgotten to publish the Slide after selecting the SliteItems? Easy mistake. Always double check if the nodes are published when you are having problems.

    If you are sure however that you had published, keep an extra eye out if this happens again, then it might be a bug.

    Glad it worked out for you anyway!

    Take care!!

Please Sign in or register to post replies

Write your reply to:

Draft