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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    238,782 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    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..

  • Verified answer
    Martin Dráb Profile Picture
    238,782 Most Valuable Professional on at

    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?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans