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)

How can I use a public constant defined in C# assembly in X++ method

(0) ShareShare
ReportReport
Posted on by 575

Hello,

I have defined a C# class that has constants defined.

namespace MySpace

{

  public class MyConstants

  {

     public const int MY_CONST_ONE = 0x01;

  }

}

 

Now in my X++ method I want use this constant. I have added a reference to above assembly in Dynamics AX AOT. But when I try use the constant I get compilation error. IntelliSense also does not show this constant.

void MyXPPMethod()

{

  int i;

;

  if(i == MySpace.MyConstants.MY_CONST_ONE)

  {

   ;

  }

}

 

How can I solve this problem?

Thanks in advance

*This post is locked for comments

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

    Hi,

    Normally Morphx doesnt support direct (public) access to object variable. The only set/get accessors are solution.

    This is standard way in AX.

    I presume the same case is for .net interop, you have to use set/get accessor.

    Artur

  • Suggested answer
    Community Member Profile Picture
    on at

    Since contants are static values in .NET assemblies

    try like this in x++ :     if(i == MySpace.MyConstants::MY_CONST_ONE)

    let us know if it works...

    Thanks

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    I also don't think you can access fields (including constant fields) from AX. Wrap the constant to a public read-only property.

    Also, the "==" operator does not marshall CLRObject[System.Int32] to X++ int, so you would get a compilation error.

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