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)

Passing and consuming C# List in AX 2012 (X++)

(0) ShareShare
ReportReport
Posted on by

Hi All,

How should I pass List object in C# to X++?

For Example,

In C# Managed Code:

public List<String> GetStringList()
{

List<String> list = new List<String>();

list.Add("One");
list.Add("Two");
list.Add("Three");

return list;

}

In X++: AX 2012 R3

static void Job9(Args _args)
{
ABJNewtonsoftJson.Program program;
List list = new List(Types::String);
ListEnumerator enumerator;
System.String netEmement;
str val1, val2;
;

program = new ABJNewtonsoftJson.Program();

list = program.GetStringList();
enumerator = list.getEnumerator();

while (enumerator.moveNext())
{
netEmement = enumerator.current();
val1 = netEmement;
}
}

// It seems like, I'm hitting error in below X++ lines:

enumerator = list.getEnumerator();

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,961 Most Valuable Professional on at

    You can't assign a .NET list to the X++ List class; they're completely different types. This kind of things can't ever work.

    Also, working with generic types is a bit difficult, so I suggest you either redesign your solution not to expose generic types, or use the non-generic System.Collections.IEnumerable interface as the type of your list variable.

    By the way, please separate tags with commas; you attached a single tag Passing and consuming C# List in AX 2012 (X++), which didn't work very well as a list of related topics.

  • Mariano Gracia Profile Picture
    on at

    Working with c# lists in x++ is just weird, in my case I needed to do it because I was consuming an external service wich uses lists, this code should work:

        ClrObject       list = new ClrObject("System.Collections.Generic.List`1[System.String]");
        ClrObject       enumerator;
        str             val1;
    
        ...
    
        list = program.GetStringList();
    
        enumerator = list.GetEnumerator();
    
        while (enumerator.MoveNext())
        {
            val1 = enumerator.get_Current();
        }


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

    I prefer System.Collections.IEnumerable because I can avoid CLRObject and hardcoded type names and I'll get IntelliSense and compile-time control.

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