Copied to clipboard

Flag this post as spam?

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


  • Jeremy Holland 20 posts 103 karma points
    Oct 05, 2016 @ 17:49
    Jeremy Holland
    0

    Runtime Binder Exception/Ambiguous call

    Hi,

    I'm getting a strange error on the "in" of a "foreach(var x in y)" statement. The code throws and exception saying the call is ambiguous between two UmbracoHelper methods. A screen shot of the error and the copied code is below. Any help would be most appreciated.

    I have verified that categories is a vanilla C# array with 2 items that are strings. The strange thing is that the foreach loop will iterate through the two items and then it tries to iterate again (and should pop out of the loop) it throws the error. Also, if I copy that entire code block and put it before the erroring block (with different variable name) it works fine.

    enter image description here

    string selectedCategories = string.Empty;
    <!-- Portfolio item start -->
    var categories = portfolioItem.GetPropertyValue(category.Name).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
    foreach (var selectedCategory in categories)
        {
            selectedCategories += Umbraco.Content(selectedCategory).Name.ToLower() + " ";
        }
    
  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Oct 06, 2016 @ 10:52
    Dennis Adolfi
    1

    Hi Jeremy.

    Have you tried to .ToString() the parameter you pass in to the Umbraco.Content() method?

    selectedCategories += Umbraco.Content(selectedCategory.ToString()).Name.ToLower() + " ";
    
  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Oct 06, 2016 @ 11:28
    Alex Skrypnyk
    100

    Hi guys,

    In perfect world its better to use strongly typed objects -

    Umbraco.TypedContent(1221).Name
    

    Thanks,

    Alex

  • Jeremy Holland 20 posts 103 karma points
    Mar 14, 2017 @ 03:49
    Jeremy Holland
    1

    I wanted to solve this issue for those of you out there that might run into this too. The problem was an ambiguous call, but the error location highlighted by Visual Studio was a red herring.

    enter image description here

    If you look at the image you see the exception hitting on the line with the foreach loop, specifically on the "in" keyword. However the error is a few lines down on a different line. Follow the red arrow to the actual exception location. This drove me crazy, but adding a .ToString() method to that parameter of the Umbraco.Content call fixes things.

Please Sign in or register to post replies

Write your reply to:

Draft