Dynamics AX and Generic collections of .Net

I'm using Dynamics AX 2009 and want to instantiate the .NET class "System.Collections.Generic.List" in X++.

Intellisense expands the class to "System.Collections.Generic.List`1" however the code cannot be compiled as the class as well as all other classes in the "System.Collections.Generic" namespace are not accepted.

Actually this type as well as every type defined in the namespace System.Collections.Generic are no regular types (are classes) but they are so called "Generics". You can see this for example when you are using a Generic in C#, where you have to specify the type of the Generic at declaration / definition (here the for example for string):

System.Collections.Generic.List<string> list;

More information about .NET Generics can be found here:
Generics (C# Programming Guide)

For Dynamics AX 4.0 Generics are not supported by the X++ language. This is outlined in the Microsoft Press book "Inside Dynamics AX" on page 111: The following feature of CLR cannot be used with X++:

  • Public fields (These can be accessed by using CLR reflection classes.)
  • Events and delegates
  • The ref parameter modifier
  • The out parameter modifier
  • Generics
  • Inner classes
  • The Container composite type
  • The Array composite type
  • Namespace declarations

Besides the "swapping" of the Generic collection into an own Assembly that is referenced back in to Dynamics AX, the only recommendation is to use the Non-Generic counterpart of the collection (see table below).

Generic   Non-Generic
System.Collections.Generic System.Collections
Collection<T> CollectionBase
Comparer<T> Comparer
Dictionary<K, V> Hashtable
List<T> ArrayList
Queue<T> Queue
SortedDictionary<K, V> SortedList
Stack<T> Stack
ReadOnlyCollection<T> ReadOnlyCollectionBase

So in our case the Non-Generic counterpart of "System.Collection.Generic.List<T>" would be "System.Collections.ArrayList".

--author: Alexander Lachner
--editor: Alexander Lachner
--date: 23/04/2009
Comments (3)

  1. Bob says:

    This make a lot of sense to me, thanks

  2. j.m.a@live.nl says:

    I use the non_generic ArrayList in AX5.0.

    How can I iterate through the ArrayList?


    I would suggest using a regular for-loop. There should be methods to get the Count of items and also Methods to access the Items.


    I see in msdn the ArrayList class has also a “GetEnumerator” Method, maybe this also works from X++.


Skip to main content