Announcements
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);
......
The error shown by the system is that the method I want to use does not exist.
Can you help me?
Thanks
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.
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.
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.
André Arnaud de Cal...
294,127
Super User 2025 Season 1
Martin Dráb
232,871
Most Valuable Professional
nmaenpaa
101,158
Moderator