Hey Umair,
It sounds like you're working on an interesting project there! Integrating X++ with C# DLLs can be a bit tricky, but I can definitely help you out.
The error you're seeing, "Method 'Test(System.Object)' is not found on type 'CSharp.Class1'," suggests that the method you're trying to call in your C# DLL (in this case, 'Test') is not matching the method signature you're using in your X++ code. Make sure that the method name and parameter types in your X++ code match exactly with what's defined in your C# DLL.
To pass a List from X++ to C# using a DLL with a passing method, you need to do the following:
Create a new CLR object in X++ and set its type to System.Collections.Generic.List<T>, where T is the type of the objects in the list.
Add the objects to the list using the Add() method.
Pass the list to the C# method as a parameter.
Here is an example of how to do this:
X++
// Create a new CLR object and set its type to `System.Collections.Generic.List<CustInvoiceTrans>`.
ClrObject myList = new ClrObject("System.Collections.Generic.List`1[CustInvoiceTrans]");
// Add the invoice items to the list.
CustInvoiceTrans custInvoiceTrans = CustInvoiceTrans::find("INV-12345");
myList.Add(custInvoiceTrans);
// Pass the list to the C# method as a parameter.
CSharp.Class1.Test(myList);
In C#, you need to declare the method that takes the List as a parameter as follows:
C#
public void Test(List<CustInvoiceTrans> invoiceItems)
{
// Do something with the invoice items.
}
Once you have done this, you should be able to pass the List from X++ to C# without any errors.
If you are getting the error message Method 'Test(System.Object)' is not found on type 'CSharp.Class1', it means that the C# method is not declared correctly. Make sure that the method is named Test() and that it takes a List of CustInvoiceTrans objects as a parameter.
If you can provide more specific details about your X++ and C# code, I can give you more targeted advice you can check with them to help with consultation. But in general, focusing on method signatures, data serialization, and error handling should help you resolve the issue and successfully pass a List from X++ to C# for inserting data as JSON via a RESTful API.
Good luck with your project, and feel free to ask if you have more questions!
public void AddLine(string itemCode, string itemName, int lineQty)
{
if (this.Lines == null)
{
this.Lines = new List<InvoiceLine>();
}
InvoiceLine line = new InvoiceLine();
line.ItemCode = itemCode;
line.ItemName = itemName;
line.Quantity = lineQty;
this.Lines.Add(line);
}
class InvoiceHeader
{
public int POSID { get; set; }
public string USIN { get; set; }
public List<InvoiceLine> Lines { get; set; }
public List<InvoiceLine> addInvoice(string itemCode, string itemName, int lineQty)
{
List<InvoiceLine> lst = new List<InvoiceLine>();
InvoiceLine objItem = new InvoiceLine();
objItem.ItemCode = itemCode;
objItem.ItemName = itemName;
objItem.Quantity = lineQty;
lst.Add(objItem);
lst.Add(objItem);
return lst;
}
}
class InvoiceLine
{
public string ItemCode { get; set; }
public string ItemName { get; set; }
public int Quantity { get; set; }
}
public class SendRequest
{
public string sendMethod(Object invoice)
{
// My logic
}
}
public List<InvoiceLine> Lines { get; private set; };
2. In X++, I would have a method that initialize the line contract from CustInvoiceTrans record.[DataContractAttribute]
public class InvoiceHeaderContract
{
public int POSID;
public str USIN;
[DataMemberAttribute('PSOID')]
public int parmPOSID(int _POSID = POSID)
{
POSID = _POSID;
return POSID;
}
[DataMemberAttribute('USIN')]
public str parmUSIN(str _USIN = USIN)
{
USIN = _USIN;
return USIN;
}
public void addInvoiceLine(str _itemCode, str _itemName, int _quantity)
{
InvoiceLineContract invoiceLine = new InvoiceLineContract();
invoiceLine.parmItemCode(_itemCode);
invoiceLine.parmItemName(_itemName);
invoiceLine.parmQuantity(_quantity);
}
}
[DataContractAttribute]
public class InvoiceLineContract
{
public str ItemCode;
public str ItemName;
public int Quantity;
[DataMemberAttribute('ItemCode')]
public str parmItemCode(str _ItemCode = ItemCode)
{
ItemCode = _ItemCode;
return ItemCode;
}
[DataMemberAttribute('ItemName')]
public str parmItemName(str _ItemName = ItemName)
{
ItemName = _ItemName;
return ItemName;
}
[DataMemberAttribute('Quantity')]
public int parmQuantity(int _Quantity = Quantity)
{
Quantity = _Quantity;
return Quantity;
}
}
public static void main(Args _args)
{
InvoiceHeaderContract invoiceHeader = new InvoiceHeaderContract();
InvoiceLineContract invoiceLine = new InvoiceLineContract();
invoiceHeader.parmPOSID(987155);
invoiceHeader.parmUSIN("USIN0");
invoiceHeader.addInvoiceLine("Item1", "TestItem", 2);
IntegrationWithFBRLibrary.SendRequest obj = new IntegrationWithFBRLibrary.SendRequest();
str message= obj.sendMethod(invoiceHeader, invoiceLine);
}
public string sendMethod(Object invoiceHeader, object invoiceLine)
{
// My logic
}
[DataContractAttribute]
public class InvoiceHeaderContract
{
public int POSID;
public str USIN;
public List invoiceLines;
[DataMemberAttribute('PSOID')]
public int parmPOSID(int _POSID = POSID)
{
POSID = _POSID;
return POSID;
}
[DataMemberAttribute('USIN')]
public str parmUSIN(str _USIN = USIN)
{
USIN = _USIN;
return USIN;
}
[
DataMemberAttribute('InvoiceLines'),
AifCollectionTypeAttribute('InvoiceLines', Types::String)
]
public List parmInvoiceLines(List _invoiceLines = invoiceLines)
{
invoiceLines =_invoiceLines;
return invoiceLines;
}
}
[DataContractAttribute]
public class InvoiceLineContract
{
public str ItemCode;
public str ItemName;
public int Quantity;
[DataMemberAttribute('ItemCode')]
public str parmItemCode(str _ItemCode = ItemCode)
{
ItemCode = _ItemCode;
return ItemCode;
}
[DataMemberAttribute('ItemName')]
public str parmItemName(str _ItemName = ItemName)
{
ItemName = _ItemName;
return ItemName;
}
[DataMemberAttribute('Quantity')]
public int parmQuantity(int _Quantity = Quantity)
{
Quantity = _Quantity;
return Quantity;
}
}
public String InsertInvoice(
string ItemCodeInv,
string itemNameInv,
string lineQty,
string lineAmount,
string UnitPrice,
string Discount)
{
Invoice objInv = new Invoice();
objInv.InvoiceNumber = "";
objInv.DateTime = DateTime.UtcNow;
objInv.PaymentMode = 1;
objInv.TotalSaleValue = 0;
objInv.TotalQuantity = 100;
objInv.TotalBillAmount = 10000;
objInv.TotalTaxCharged = 10;
objInv.Discount = 10;
objInv.FurtherTax = 100;
objInv.InvoiceType = 1;
objInv.Items = Items();
List<InvoiceItems> Items()
{
List<InvoiceItems> lst = new List<InvoiceItems>();
InvoiceItems objItem = new InvoiceItems();
objItem.ItemCode = ItemCodeInv;
objItem.ItemName = itemNameInv;
objItem.Quantity = lineQty
objItem.TotalAmount = Convert.ToDouble(lineAmount);
objItem.SaleValue = Convert.ToDouble(UnitPrice);
objItem.Discount = Discount;
lst.Add(objItem);
lst.Add(objItem);
return lst;
}
}
André Arnaud de Cal...
294,137
Super User 2025 Season 1
Martin Dráb
232,879
Most Valuable Professional
nmaenpaa
101,158
Moderator