Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Calling X++ code from C# (AX 7)

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have an X++ method (residing in the Fleet Management module) that I need to call within a C# class library. 

I have used the below link as a guide -> https://ax.help.dynamics.com/en/wiki/writing-business-logic-in-c-and-x-source-code/

Basically, I have a c# console application, and I am making a call to this ax method as below

    using Dynamics.AX.Application;
    using Microsoft.Dynamics.Ax.Xpp;
    class Program
    {
        static void Main(string[] args)
        {
            DFM_H5PortalSerializer axClass = new DFM_H5PortalSerializer();
            axClass.processString("test");
        }
}

The ax Class is shown in intellisense, however, as soon as I run it, i get the following exception:

"An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'Dynamics.AX.FleetManagement, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."

 


Any ideas on what is causing the issue and how to solve it?

Thanks

*This post is locked for comments

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: Calling X++ code from C# (AX 7)

    Yes, if you want a console application talking to Dynamics AX, you need a web service.

    Don't forget that production environments of Dynamics AX run in Azure, so how else could your console application talk to them?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Calling X++ code from C# (AX 7)

    Thanks for you reply Martin. So basically, I would need to use a JSON or SOAP service instead to expose functionality to my c# console application..

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: AX7 - Calling X++ code from C#

    You can't just call AX code from outside Dynamics AX, such as in your console application.

    But you can write C# code (there you can refer to AX types) and execute it from Dynamics AX, which is what the wiki talks about.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans