web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Clr Interop Marshal: Unsupported type

(0) ShareShare
ReportReport
Posted on by 362

Hi All,

i have written the below method inside a c# class library , i have build it successfully and added it to AOT ,

i'm  able to access the class and method in X++ , but not able to loop through the string array which is returned by the dotnet code.

can some one help me with some code snippet 

public string[] customersinfo()
{

string city, firstname, lastname, custid;
string[] details = new string[4];

firstname = "";
lastname = "";
city = "";
custid = "";

details[0] = firstname;
details[1] = lastname;
details[2] = city;
details[3] = custid;

return details;
}

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: Clr Interop Marshal: Unsupported type

    The bug must be in how you work with the array in X++, so please show us the right piece of code. The code above is fine, although you can greatly simplify it, if you want:

    return new[] { "", "", "", "" };

    Note that using an object representing the customer would be a better design, because you would get IntelliSense, you could use different types and so on.

  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: Clr Interop Marshal: Unsupported type

    Your piece of code does not seem to be connected to .Net values.

    Didn't you mean to use the .Net string array as System.String[] instead, and associate/extract values from there?

  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: Clr Interop Marshal: Unsupported type

    It actually is C# code; string is in alias of System.String (it would be str in X++).

  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: Clr Interop Marshal: Unsupported type

    I was referring to his looping through piece of code inside AX which consumes his C# method pasted above, that he failed to show. That is why I tried to suggest to marshal it to the same type in X++, then extract values from there.

  • Naresh Kumar Profile Picture
    362 on at
    RE: Clr Interop Marshal: Unsupported type

    Hi Martin ,

    Below is the piece of code that you have written

    CustomerDetails.Customers obj = new CustomerDetails.Customers();

    System.String[] _details = new System.String[30]();

    int i ;

       _details = obj.customersinfo();

    for(i=0;i<_details.get_Count();i++)

       {

          info(_details.get_Item(i);

       }

    Regards,

    Naresh

  • Naresh Kumar Profile Picture
    362 on at
    RE: Clr Interop Marshal: Unsupported type

    Hi Vilmos,

    how to marshall the code

    this is the below piece of code i have written and im getting the error

    Error executing code : wrong argument types for comaprison

    CustomerDetails.Customers obj = new CustomerDetails.Customers();

    System.String[] _details = new System.String[30]();

    int i ;

       _details = obj.customersinfo();

    for(i=0;i<_details.get_Count();i++)

       {

          info(_details.get_Item(i));

       }

  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: Clr Interop Marshal: Unsupported type

    There is no need to initialize _details and immediately throw the value away and replace it with the value from customersinfo(), therefore your code can be simplified to this:

    CustomerDetails.Customers obj = new CustomerDetails.Customers();
    System.String[] details = obj.customersinfo();
    int i;
    
    for (i = 0; I < details.get_Count(); i++)
    {
        info(_details.get_Item(i));
    }

    Now please tell us which line is throwing the error. Isn't the one with info()?

  • Naresh Kumar Profile Picture
    362 on at
    RE: Clr Interop Marshal: Unsupported type

    Yes martin ,info statement is giving the error

    _details.get_count() is giving the correct count (i.e 4)

    could you please tell me where is the error

  • Verified answer
    Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: Clr Interop Marshal: Unsupported type

    It's related to marshalling (the conversion from .NET types to X++), not the number of array elements.

    One solution is using clr2XppStr(), such as info(clr2XppStr(_details.get_Item(i)));.

    Alternatively your can assign the value to a local str variable and then use this X++ string variable in info().

    It's a certain limitation of how marshalling of .NET types in implemented in AX.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Clr Interop Marshal: Unsupported type

    Try to marshal it like:

    str strValue;

    strValue = ClrInterop::getAnyTypeForObject(_details.get_Item(i));

    info(strValue);

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
NNaumenko Profile Picture

NNaumenko 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans