Copied to clipboard

Flag this post as spam?

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


  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Sep 21, 2012 @ 14:06
    Jeavon Leopold
    0

    Razor @Library Extension - Extension methods cannot be dynamically dispatched

    I'm trying to create library extensions which accept parameters however when I try to pass in a value from Model I get the error:

    Error 2 'umbraco.MacroEngines.Library.RazorLibraryCore' has no applicable method named 'Foo' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax

    My method:      
      public static string Foo(this RazorLibraryCore library, string test)
            {
                return "Bar: "+ test;
            }
    This works fine when called like @Library.Foo("aa") but if I try @Library.Foo(Model.Name) I get the error above, what am I doing wrong?
    Thanks for any suggestions!

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Oct 15, 2012 @ 12:44
    Jeavon Leopold
    1

    Just in case anyone comes accross this, the solution is that the dynamic must be cast as the type defined, e.g @Library.Foo((String)Model.Name)

Please Sign in or register to post replies

Write your reply to:

Draft