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)

pass IEnumerable object from X++ in C# method ?

(0) ShareShare
ReportReport
Posted on by 3,175

Hi, i have a .Net assembly which i consume in AX 2009. One of the classes in this assembly has a method which takes IEnumerable<string> as input parameter. How do i call this method from X++ ?

Eg:  In .net assembly i have
Public Static Class ClassA
  {
     .....
     .....

     public static void method1(IEnumerable<string>)
      {
      }
  }
Thanks,
San

*This post is locked for comments

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

    Unfortunately AX doesn't work very well with generic types, often it's easier to write a proxy in .NET and expose only non-generic types to AX.

    But in your case, solution is not difficult - you can simply use an array of strings, because Array implements IList<T> and ICollection<T>, both extending IEnumerable<T>:

    System.String[] arr = new System.String[3]();
    ;
    arr.SetValue("a", 0);
    arr.SetValue("b", 1);
    arr.SetValue("c", 2);
    ClassA::method1(arr);
  • San Artham Profile Picture
    3,175 on at

    perfect Martin, this works. I didn't know that Array implements IList and ICollection , looks like this changed in .Net 2.0 and it implements it only at run-time.

    Thanks again,

    San

    http://sanartham.blogspot.com/

  • Maqk Profile Picture
    844 on at

    Martin, i benefited from your answer in my situation as well,

    but just to mention, i was not able to pass a 2 dimensionsional array. My C# method required a 2d object array, and as i passed it from X++, every time the Dynamics dev environment crashed.

    The way i fixed was to declare an Object variable in the CLR method and pass multidimensional array from X++

    Any specific reasons this mismatch ?

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

    I tried it in AX2012 and I didn't experience any crashes, but AX complained about incompatible types. It was the same regardless I used System.String[,] or System.Array.

    Because the value can be successfully sent through CLRObject or System.Object instance, I guess that AX compiler is just not smart enough and doesn't recognize the type correctly. Why is it so, I don't know.

    If you're in AX2012, you can use a simple workaround - just cast the parameter by the "as" operator, e.g. SomeNetMethod(arr as System.Object).

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