web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Error when using the RunAs command in AX2012R2

(2) ShareShare
ReportReport
Posted on by 301,069 Super User 2025 Season 2

Hi all,

I just posted a blog about standard batch jobs being created when you install AX2012. You can read the post here: www.kaya-consulting.com/.../about-the-standard-batch-jobs-in-ax2012

I tried to create a class to create the standard batch jobs running as the Admin user.

7041.6_2D00_1_2D00_2014-09_2D00_47_2D00_18.png

Compilation was ok. At runtime I get the error below.

It is stating the method does not exist, but actually it does exist!

What is the cause of this error? Also the second runas commandline has the same error. I also tried another static method on another class and this one was working OK. What is missing that these static methods cannot be executed in the 'runas' command?

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    X++ code that is executed by the runAs function must run as .NET Framework CIL.

    If CIL has not been generated for the target static method, an error message indicates that the method is not found.

    For details read Remarks in http://msdn.microsoft.com/en-us/library/aa893873.aspx

    for details about "X++ Compiled to .NET CIL [AX 2012]" see http://msdn.microsoft.com/en-us/library/gg839855.aspx

  • Community Member Profile Picture
    on at

    as per my understanding you need to do CIL compilation to resolve this issue.

    Please verify.

  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi MasterVBNet,

    Thanks for your answer. I forgot to mention that CIL is compiled. I also was aware of the first link you sent.

    I run a new CIL compile and it still raises the error.

    I think the problem could be related to the second link. I tried to call two standard classes. I will investigate this one for the two methods used in the sample above.

    @Nitesh, I already sent you a mail before on what is a suggested answer and submitting a same answer as someone else already did. Your anwser is irrelevant in this case. Please reread my private mail.

  • PA-22040759-0 Profile Picture
    6,194 on at

    Hi André,

    I was wondering if your problems could be caused by testing on a system with hot-swapping enabled. I'm then thinking that the user you use for RunAs has a different version of the compiled dll!?

    Regards,

    Palle

  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi Palle (and MasterVBNet),

    I will check your suggestions tomorrow.

  • Gertjan Profile Picture
    1,200 on at

    Hi André,

    It seems not to depend on your CIL compilation or hot swapping. I tried in an AX2012 R2 environment and I got exactly the same error. I cannot find a reason for it. The synchronize method in the same class is accepted in the runAs command however, so it seems to be caused by this specific method.

  • Suggested answer
    Community Member Profile Picture
    on at

    Dear Mr Andre Arnaud de Calavon,

    I dare once gain to reply your question with suggested answer that the error what you are getting is due of the CIL compilation.

    Please follow following link

    http://msdn.microsoft.com/en-us/library/aa893873.aspx

    Please check the Remarks section, which clearly says that the error what you are getting is due to the method not having CIL code.

    Please verify.

    What i understand that 'createBatchJob' method in the class is not getting CIL generated, as you said you have already did it.

    I will explore further and update you why this is happening like this,

    currently i think it is due to the code in the method which is not allwoing CIL to get generated for the method.

  • Community Member Profile Picture
    on at

    Hi Andre,

    Just to ensure that CIL-Compilation is not the reason,

    See if the steps mentioned by AxWonders in his blog would help: axwonders.blogspot.com/.../solving-error-cil-generator-found.html

    He says to Stop-AOS, Delete files in XppIL Folder, Start-AOS, Compile, and Generate CIL

    Please read comments between AXWonders and Tommy Skaue

  • Verified answer
    dolee Profile Picture
    11,279 on at

    Hey Andre,

    Try this:

    In the static method you plan to call with runAS, add a container parameter there.

    For example, in the createBatchJob method for SysUserLicenseMiner, change the method declaration to below will get pass the error.

    public static server void createBatchJob(container _c)

    I don't know if it's related, but I came to the above by playing with the Global::runClassMethodIL method. When I call a static method without the container parameter I would get an error saying the parameter I passed into the static method is incorrect. So I apply the same logic here and it seems to work.

    P.S. I didn't check whether the batch job was added. I did test with a custom static method and I get the correct return value.

    Kind Regards,

    Dominic

  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi All,

    Many thanks for sharing a lot of tips. The tip provided by Dominic was the link which answered the question.

    Only providing the a parameter in the method declaration on the createBatchJob class is solving the issue. You don't have to specify the parameter in the RunAs command itself, you can leave it blank. 

    I searched for some more samples in the application itself and found some more "empty containers" used in combination with the RunAs command.

    @MasterVBNet, Nitesh, I can confirm I deleted the files in the XppIL directory as well, so the CIL was clean. Adding the parameter in the createBatchJob was the missing link.

    To let you know: I don't want to change the standard logic or prevent it as much as possible.

    So in my new class I created an additional method "doIt". This method looks like:

    server static public void doIt(container _c)

    {

       SysSecurityDynamicRoleAssignment::createBatchJob();

       SysUserLicenseMiner::createBatchJob();

    }

     

    From the main method I now have the next RunAs call:

    server static public void main(Args _args)

    {

       RunAsPermission         perm;

       #Admin

       perm = new RunAsPermission(#AdminUser);

       perm.assert();

       runAs(#AdminUser,classNum(TestCreateBatches),staticMethodStr(TestCreateBatches,doIt));

       CodeAccessPermission::revertAssert();

       info ("done");

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans