Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

SET LIST OF C# .NET 3,5 DLL FROM AX 2009 X++

Posted on by 10

Hello, I am working with some webservice call and I have a C# List of object which am to set from x++.

This code is assembled on the .net Framework 3.5, the code I have in C# is:

public List<PurchLine>  line { get; set; }      

private List<PurchLine> lineList = new List<PurchLine>();        

        public void AddLine(PurchLine line)

        {

            lineList.Add(line);

        }

        public List<PurchLine> GetLine()

        {

            return lineList;

        }

On the other hand, in AX 2009,

I have created a class in X++ to call this code. My problem is that when working with the Purchline list, I don't perform the Set_Line() method. Mi code is :

.....

while select purchLine
where purchLine.PurchId == purchTable.PurchId
{

d365PurchLine = new FinishProductAgainstOrder.PurchLine();

d365PurchLine.set_lineNum(num2str(purchLine.LineNum, 6, 2, -1, -1));
d365PurchLine.set_itemId(purchLine.ItemId);


d365purchTable.AddLine(d365PurchLine);

}

d365PurchTable.set_line(d365PurchTable.GetLine());


resultDirmemo = d365PurchTable.Serialize(d365PurchTable);

......

3005.Captura-de-pantalla-2022_2D00_04_2D00_07-a-las-21.58.46.png

The error shown by the system is that the method I want to use does not exist.

Can you help me?

Thanks

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: SET LIST OF C# .NET 3,5 DLL FROM AX 2009 X++

    If the type of "list" variable is something like ILIst, you'll be able to replace CLRObject with such a type.

    No worries about code formatting. It's normal that you don't know all the features from the beginning - it's exactly why I point to it. :)

    Another important thing is that if you get an answer, you should verify it. It'll make clear what the question has already been answered and what the answer was. It'll help other users of this forum; e.g. they can easily navigate to answers and skip the rest of discussion. See details in Suggested and Verified Answers.

  • jgimenez Profile Picture
    jgimenez 10 on at
    RE: SET LIST OF C# .NET 3,5 DLL FROM AX 2009 X++

    Hello Martin.

    Thank you very much for the quick response, I really appreciate it.

    I have tried what you have advised me and with the non-generic collection (Ilist) I still had problems adding the PurchLine object inside the list.

    Anyway, in the end declaring in my X++ code a CLRObject variable to assign the value to, it worked perfectly.

    Finally, sorry for miscopying the text in the forum, it's the first time I'm writing and I didn't know about it, I'll keep in mind next time your tip when copying source code in the forum.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: SET LIST OF C# .NET 3,5 DLL FROM AX 2009 X++

    Because .NET Interop from X doesn't support generic types, you'll make your life much easier if you don't expose generic types in your C# code. For example, create a concrete type (e.g. PurchLineList) instead of using List<T>, or use a non-generic collection (ArrayList,  IList).

    If you insist on using generic types anyway, try assigning the value through a CLRObject variable.

    CLRObject lineList = d365PurchTable.GetLine();
    d365PurchTable.set_line(lineList);

    By the way, please always use Insert > Code (in this rich formatting view) to paste source code to this forum. It'll be much eaiser to read.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans