Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Delegate between C# and X++

(0) ShareShare
ReportReport
Posted on by 15

Hi all!

Is it possible to subscribe from X++ to a C# event in Dynamics 365 Finance and Operations?

My goal is the following:

I have a project in C# that is responsible for receiving messages from an Azure queue service (Service Bus to be specific), the success would be that this application is always active listening to messages from the queue, receive them as JSON and send it to X++ for a specific process to continue.

Now let me explain my situation...

For compatibility issues with my X++ project, I must use the .NET Framework 4.6 in my C# project and with this version of .NET I was only able to download the Microsoft.Azure.ServiceBus Version 1.0.0 library (I know it's obsolete but It's the only one I could install.

This is the code I used to receive the messages  Use Azure Service Bus queues with .NET (old version) - Azure Service Bus | Microsoft Docs

My main problem is determining how to send the information to X++ as it arrives in C#. Investigating, the most viable option seemed to me is using delegates and events, so I added the following to the documentation code.

Class attributes

  • public delegate void MessageReceivedEventHandler(string message);
  • public event MessageReceivedEventHandler MessageReceived;

And I modified the ProcessMessagesAsync method to add the event.

5415.img2.png

After this I created a console application (C#) to test it, this is the code.

0763.img4.png

I sent 3 messages to the queue and these were appearing in the test console application (it works perfectly).

8750.img1.png

I tried to replicate the exact same thing in X++, like this:

6567.img5.png

But it doesn't work, the process hangs and never shows me any message when I send data to the queue.

Something additional is that in the line queueListener.MessageReceived += eventhandler(MntServiceBusTest::ShowMsg), MessageReceived doesn't appear to me, the options that appear are

0272.img6.png

However, if I use add_MessageReceived I get that the C# class doesn't contain any delegates with that name and it won't let me compile the X++ project.

I hope someone can give me an idea of ??how to achieve my goal, I spent days with this situation.

Regards

  • Martin Dráb Profile Picture
    231,723 Most Valuable Professional on at
    RE: Delegate between C# and X++

    What about subscribing to the event in C# and let the event handler call an AX method?

    For example, your QueueListener class could have a property for a logger object, defined at an interface (e.g. ILogger). You'll implement the interface in an X++ class and pass an instance of this class to QueueListener. The event handler will then call a method for dealing with messages.

    By the way, it could be interesting to see what CIL was generated for the case with += eventhandler. You can use a CIL decompiler for that - there is no decompiler back to X++, but you can decompile it to C# and see the logic there.

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Delegate between C# and X++

    docs.microsoft.com/.../write-business-logic

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,865 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans