I had the same error and found the solution by making below addition in code
public static void SerializeSalesPaymentEntryObject(string filename)
{
try
{
DateTimeFormatInfo dateFormat = new CultureInfo("en-US").DateTimeFormat;
// Instantiate an eConnectType schema object
eConnectType eConnect = new eConnectType();
// Instantiate a SOPTransactionType schema object
SOPTransactionType transType = new SOPTransactionType();
// Instantiate a taCreateSopPaymentInsertRecord_ItemsTaCreateSopPaymentInsertRecord XML node object
taCreateSopPaymentInsertRecord_ItemsTaCreateSopPaymentInsertRecord[] crPaymentArr = new
taCreateSopPaymentInsertRecord_ItemsTaCreateSopPaymentInsertRecord[1];
taCreateSopPaymentInsertRecord_ItemsTaCreateSopPaymentInsertRecord crPayment = new
taCreateSopPaymentInsertRecord_ItemsTaCreateSopPaymentInsertRecord();
taSopHdrIvcInsert salesHdr = new taSopHdrIvcInsert();
salesHdr.SOPTYPE = 3;
salesHdr.DOCID = "STDINV";
salesHdr.SOPNUMBE = "STDINV2405";
salesHdr.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy", dateFormat);
salesHdr.CUSTNMBR = "AARONFIT0001";
salesHdr.BACHNUMB = "AUG31";
salesHdr.UpdateExisting = 1;
// Create an XML serializer object
XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
crPayment.SOPTYPE = 3;
crPayment.SEQNUMBR = 1;
crPayment.SOPNUMBE = "STDINV2405";
crPayment.CUSTNMBR = "AARONFIT0001";
crPayment.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy", dateFormat);
crPayment.DOCAMNT = 2.5M;
crPayment.PYMTTYPE = 5;
crPayment.Action = 1;
crPayment.CHEKNMBR = "0010010001";
crPaymentArr[0] = crPayment;
transType.taCreateSopPaymentInsertRecord_Items = crPaymentArr;
transType.taSopHdrIvcInsert = salesHdr;
SOPTransactionType[] rmCashReceiptsTypeMaster = { transType };
eConnect.SOPTransactionType = rmCashReceiptsTypeMaster;
// Create objects to create file and write the customer XML to the file
FileStream fs = new FileStream(filename, FileMode.Create);
XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
// Serialize the eConnectType object to a file using the XmlTextWriter.
serializer.Serialize(writer, eConnect);
writer.Close();
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}