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

I have the same question (0)
  • ergun sahin Profile Picture
    8,826 Moderator on at

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

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    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.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans