Error executing code: The method has been called with an invalid number of parameters.


One of the great features of Dynamics AX is the rich integration with other applications or services. The Dynamics AX client is for example exchanging data with Microsoft Office applications like Microsoft Office Excel or Microsoft Office Outlook.

Some of these interactions are performed using COM. When the Dynamics AX Client is using COM for the data exchange in certain situation it can happen you are getting confronted with one of the following error message:

  • Error executing code: The method has been called with an invalid number of parameters
  • The number of arguments provided is different from the number of arguments accepted by the method

Certain situations means, that you are not always getting this error message but only sometimes and the error is not reproducible. The chance of getting this error message is higher when you continue to work in other applications while the Dynamics AX client is performing the COM operation.

One reason for running into this issue can be if the Windows Operating System is replacing the Dynamics AX application window by a ghost window.

When Dynamics AX starts a lengthy COM operation, it is not responding to messages sent by the Windows Operating System in time. So Windows supposes Dynamics AX has stopped responding. When this happens the Dynamics AX application window is replaced by a ghost window until Dynamics AX resumes. Window ghosting is a nice feature that allows the user to minimize, move or close the main window even if the application is not responding. You can easily identify a ghost window as it shows (Not responding) in the window title.

Unfortunately the replacement of the Dynamics AX application window by the ghost window can interfere the COM operation and result in the above error message.

Therefore it can be helpful to turn window ghosting for the Dynamics AX Client off:

  1. Locate the Dynamics AX shortcut in the Windows Start Menu
  2. Click with the right mouse button on the shortcut and select Properties
  3. Go to the Compatibility tab
  4. Enable the checkbox Run this program in Compatibility mode for and select Windows XP (Service Pack 2)

Please note:

  • We have seen this issue most on Windows Vista and Windows Server 2008 but this issue is not limited to those two
  • Window ghosting is not the only cause of this issue, so you might continue to see the error message even if window ghosting was turned off

More information about window ghosting:

–author: Alexander Lachner
–editor: Alexander Lachner
–date: 18/06/2009
–updated: 03/08/2010
Comments (6)

  1. Tom Dc says:

    Hello Alexander,

    Do you know which are the other causes then the noGhost feature? If I want to create an Application Compatibility fix for the AX32 client, which are the other fixes that must be applied?

    Best regards,

    Tom

  2. EMEAAXTec says:

    Hi Tom,

    Unfortunately there exists several possibilities resulting in this situation and disabling Window Ghosting has proven as workaround in some of those. By now we have found some other workarounds as well. But so far there is no once for all solution.

    Here are the workarounds we know so far…

    Workaround 1:
    Disable Window Ghosting as described in this post.

    Workaround 2:
    Debug the X++ code down to the line that is causing the error. Once identified, insert one line before this statement a call to the yield method of the xInfo class.

      Example:
      infolog.yield();
      namespace = outlook.getNamespace(#mapidef);

    Workaround 3:
    Debug the X++ code down to the line that is causing the error. Once identified, place the statement inside a try / catch block. In the catch block simply retry the operation.

      Example:
      int retryCount = 3;
      //…

      try
      {
         namespace = outlook.getNamespace(#mapidef);
      }
      catch(Exception::Error)
      { 
         retryCount–;

         if(retryCount > 0)
            retry;
         else
            throw(Exception::Error);
      }

    Best regards,
    Alex
    (Member of the EMEA Dynamics AX Support Blog Team)

  3. Polat says:

    Dear alex, is there any solution except these workarounds. I have 50 thousand of records to insert a table using excel import. I get this error in a different row when i process the excel import .Our server system is windows 2008.

    Best Regards

    ————————————-

    Hi, are you facing exactly the same situation as described above? If so have you tried the workaround? Else there could be other reasons as well.

     

    –Anup

  4. Eddy says:

    Thanks for the article. It really helped me solve my problem.

  5. Eduardo says:

    I came up with a similar solution before getting to this post. However, the way you explained the issue is very good and clear … thank you!

    http://axwonders.blogspot.com/