0

I'm on the latest hotfix (v13.0.151).

I followed the documentation to add a custom macro method but it doesn't register. Below is what I did:

In a separate assembly (which has a dummy class annotated with [assembly: AssemblyDiscoverable]) I have my macro methods:

//[assembly: RegisterExtension(typeof(SOSMacroMethods), typeof(SOSMacroNamespace))] //tried with and without
public class SOSMacroMethods : MacroMethodContainer
{
    [MacroMethod(typeof(string), "test method", 0)]
    public static object MyTestMethod(EvaluationContext context, params object[] parameters)
    {
        return "yayyy registered";
    }
}

And the module and namespaces as so:

[assembly: RegisterModule(typeof(SOSMacroModule))]

public class SOSMacroModule : Module
{
    public SOSMacroModule()
        : base("SOSMacros")
    {
    }

    protected override void OnInit()
    {
        base.OnInit();

        MacroContext.GlobalResolver.SetNamedSourceData("SOS", SOSMacroNamespace.Instance);
    }
}

[Extension(typeof(SOSMacroMethods))]
public class SOSMacroNamespace : MacroNamespace<SOSMacroNamespace>
{

}

I then compiled this and added it to my admin solution as an existing project and added a reference to it too. I then rebuilt the admin solution.

When I go to the admin interface I don't get it in the macro editor and when I try to debug it I get the error log message:

CMS.MacroEngine.EvaluationException: Exception occurred while evaluation of the expression ' <snipped for brevity>': Method 'MyTestMethod' not found, please check the macro or the method declaration.

I get the same issue when trying to resolve the macro on my live site too. Edit: working on live site now though I've made no changes

This works in my K12 Portal solution and from what I can gather the only changes are sharing the macros between presentation and admin in K13.

Is there something I'm missing?

2
  • 1
    I would recommend following the example in the documentation as it is. I just tried it and it works fine. I assume you added the AssemblyDiscoverable attribute to the AssemblyInfo.cs class, right? Is the custom macro assembly DLL created in the BIN folder after building the solution? Also, what is the SOSMacroNamespace.Instance in the SetNamedSourceDataCallback? Where it is defined and what is the code?
    – jurajo
    Commented Jun 4 at 7:41
  • @jurajo that put me on the right path, thanks. The dll wasn't going into the cms/bin folder so I copied it manually and now it works
    – rory
    Commented Jun 4 at 8:00

0

Browse other questions tagged or ask your own question.