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)

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
    239,057 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
    239,057 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans