[D365] error Parameter name: The static extension method has not been set properly

While upgrading an AX2012 R3 solution, I trapped into the following error:

Abnormal termination with unhandled exception.
System.ArgumentNullException: Value cannot be null.
Parameter name: The static extension method has not been set properly

The extension class looks like this:

/// <summary>
/// Extension for table <c>CustBankAccount</c>
/// </summary>
[ExtensionOf(tablestr(CustBankAccount))]
final class CustBankAccountROBS_Extension
{
    public static CustBankAccountId findOrCreateBankAccountIDROBS(
        CustAccount                             _custAccount,
        BankStatementAccountNumOrIBANROBS       _NumOrIBAN,
        BankStatementBankRegNumOrSWIFTNoROBS    _regNumOrBIC)
    {
        CustBankAccount custBankAccount;
        CustParameters  custParameters  = CustParameters::find();

        select firstOnly1 AccountId from custBankAccount
            where   custBankAccount.CustAccount     == _custAccount
                &&  custBankAccount.SWIFTNo         == _regNumOrBIC
                &&  custBankAccount.BankIBAN        == _NumOrIBAN;

        if (!custBankAccount.RecId)
        {
            ttsBegin;
            // some other stuff ...
            custBankAccount.CustAccount     = _custAccount;
            custBankAccount.SWIFTNo         = _regNumOrBIC;
            custBankAccount.BankIBAN        = _NumOrIBAN;
            custBankAccount.insert();
            ttsCommit;
        }


        // some other stuff ...
        return custBankAccount.AccountID;
    }

    public static CustBankAccountId getFreeBankAccountIdROBS(
        CustBankAccountId   _accountId,
        CustAccount         _custAccount,
        int                 _index = 0)
    {
        CustBankAccount     custBankAccount;
        CustBankAccountId   accountId;
        ;

        accountId           = _accountId;

        if (_index > 0)
        {
            accountId       = strFmt('%1_%2', _accountId, _index);
        }

        select firstOnly1 RecId from custBankAccount
            where   custBankAccount.CustAccount     == _custAccount
                &&  custBankAccount.AccountID       == accountId;

        // some other stuff ...

        return accountId;

    }

}

In the beginning of this post I said "trapped" because the error message made me search the cause within the extension class itself. The root cause was in another class which calls the method of this extension.
The call:

ledgerJournalTrans.CustVendBankAccountId = CustBankAccount::findOrCreateBankAccountIDROBS(custAccount, ...

Maybe you already noticed by now that the method is called as a static method but the declaration is not static!

To get rid of the compile error, simply correct the modifier to make it a static method.

Until now I could not find the reason why the automatic convert of LCS removed the static signature on this method...

Hope this example helps you in some of your cases!

Robin

Software Engineer / Application Developer

Subscribe to robsCode

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!