Search code examples
c#rpag1ant

How to fix the "Expected Command postfix" error?


I am trying to create an add-on with a command called "mycommand". After building it with VS 2019 Community edition and putting it in the add-on G1ANT.Robot/Add-on folder, it causes G1ANT to crash on start up or displays the error message like so:

Error Message

Same message also exists in the log file when G1ANT Studio crashes.

Here is the C# code for the Addon:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using G1ANT.Language;

// Please remember to refresh G1ANT.Language.dll in references

namespace G1ANT.Addon.MyAddon1
{
    [Addon(Name = "Addon", Tooltip = "...")]
    [Copyright(Author = "G1ANT LTD", Copyright = "G1ANT LTD", Email = "[email protected]", Website = "www.g1ant.com")]
    [License(Type = "LGPL", ResourceName = "License.txt")]
    //[CommandGroup(Name = "", Tooltip = "")]
    public class Addon : Language.Addon
    {

        public override void Check()
        {
            base.Check();
            // Check integrity of your Addon
            // Throw exception if this Addon needs something that doesn't exists
        }

        public override void LoadDlls()
        {
            base.LoadDlls();
            // All dlls embeded in resources will be loaded automatically,
            // but you can load here some additional dlls:

            // Assembly.Load("...")
        }

        public override void Initialize()
        {
            base.Initialize();
            // Insert some code here to initialize Addon's objects
        }

        public override void Dispose()
        {
            base.Dispose();
            // Insert some code here which will dispose all unecessary objects when this Addon will be unloaded
        }

    }
    [Command(Name = "mycommand", Tooltip = "This is a test command")]
    public class mycommand : Command
    {
        public class Arguments : CommandArguments
        {
            // Enter all arguments you need
            [Argument(Required = true, Tooltip = "Enter some text here")]
            public TextStructure Text { get; set; }

            [Argument(Tooltip = "Result variable")]
            public VariableStructure Result { get; set; } = new VariableStructure("result");
        }

        public mycommand(AbstractScripter scripter) :base(scripter)
        {

        }

        // Implement this method
        public void Execute(Arguments arguments)
        {
            // Do something: for example, display argument text on the screen
            RobotMessageBox.Show(arguments.Text.Value);
            // Set result variable to the calculated text argument
            Scripter.Variables.SetVariableValue(arguments.Result.Value, new TextStructure(arguments.Text.Value));

            // If you need, set another variable to the calculated text argument
            Scripter.Variables.SetVariableValue("other", new TextStructure(arguments.Text.Value));
        }
    }

}

I am following this Command template from the G1ANT.Sdk GitHub repository: (Link)


Solution

  • Your mycommand class is incorrectly named. The requirement is to name it exactly the same as the name of the command and adding the "Command" postfix.

    To solve the problem, simply rename your class to MyCommandCommand.