Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
---------This is front end part ----

error //
Unable to cast object of type 'System.Object[]' to type 'CRMWCFSERVICES.InvReqClass[]'."}


Dim listReq As New List(Of InventoryRequest)


For Each Row As DataRow In ds.Tables(0).Rows
InvReq.REQUESTNUMBER = txtReqRefNo.Text
InvReq.PROJECTNAME = cmbProg.Text
InvReq.PARTNUMBER = Row("PartNo").ToString()
InvReq.EnggName = txtUserID.Text
InvReq.DEPTID = Session("DeptID")
InvReq.ITEMID = Row("ItemId").ToString
InvReq.QTY = txtRQty.Text
listReq.Add(InvReq)

'invClient.SendrequestToSL(InvReq.REQUESTNUMBER, InvReq.PROJECTNAME, InvReq.PARTNUMBER, InvReq.EnggName, InvReq.DEPTID, InvReq.ITEMID, InvReq.QTY)
Next


Dim arrList As New System.Collections.ArrayList(listReq)

// error is coming in last line
invClient.SendrequestToSL(arrList.ToArray())


--------------wcf servives ----------


        public string SendrequestToSL(List<InvReqClass> ListInvReqClass)
        {
            
        if (ListInvReqClass.Count == 0) { throw new ArgumentNullException("ListRequisitionRequest"); }
            var xmlElements = new XElement("ListRequisitionRequest",

                  from RequisitionRequest in ListInvReqClass

                  select new XElement("RequisitionRequest",
                            new XAttribute("ReqNoteNumber", RequisitionRequest.ReqNoteNumber),
                            new XElement("Qty", RequisitionRequest.Qty),
                            new XElement("ProgramName", RequisitionRequest.ProgramName),
                            new XElement("PartNo", RequisitionRequest.PartNo),
                            new XElement("ItemId", RequisitionRequest.ItemId),
                            new XElement("EnggName", RequisitionRequest.EnggName),
                            new XElement("DeptId", RequisitionRequest.DeptID)
                             ));
  return xmlElements.ToString();
        }

What I have tried:

<pre>---------This is front end part ----

  Dim listReq As New List(Of InventoryRequest)


        For Each Row As DataRow In ds.Tables(0).Rows
            InvReq.REQUESTNUMBER = txtReqRefNo.Text
            InvReq.PROJECTNAME = cmbProg.Text
            InvReq.PARTNUMBER = Row("PartNo").ToString()
            InvReq.EnggName = txtUserID.Text
            InvReq.DEPTID = Session("DeptID")
            InvReq.ITEMID = Row("ItemId").ToString
            InvReq.QTY = txtRQty.Text
            listReq.Add(InvReq)

            'invClient.SendrequestToSL(InvReq.REQUESTNUMBER, InvReq.PROJECTNAME, InvReq.PARTNUMBER, InvReq.EnggName, InvReq.DEPTID, InvReq.ITEMID, InvReq.QTY)
        Next

        
        Dim arrList As New System.Collections.ArrayList(listReq)

// error is coming in last line
        invClient.SendrequestToSL(arrList.ToArray())


--------------wcf servives ----------


<pre>
        public string SendrequestToSL(List<InvReqClass> ListInvReqClass)
        {
            
        if (ListInvReqClass.Count == 0) { throw new ArgumentNullException("ListRequisitionRequest"); }
            var xmlElements = new XElement("ListRequisitionRequest",

                  from RequisitionRequest in ListInvReqClass

                  select new XElement("RequisitionRequest",
                            new XAttribute("ReqNoteNumber", RequisitionRequest.ReqNoteNumber),
                            new XElement("Qty", RequisitionRequest.Qty),
                            new XElement("ProgramName", RequisitionRequest.ProgramName),
                            new XElement("PartNo", RequisitionRequest.PartNo),
                            new XElement("ItemId", RequisitionRequest.ItemId),
                            new XElement("EnggName", RequisitionRequest.EnggName),
                            new XElement("DeptId", RequisitionRequest.DeptID)
                             ));
  return xmlElements.ToString();
        }
Posted
Updated 4-Jul-19 23:39pm
Comments
F-ES Sitecore 5-Jul-19 5:31am    
What line does the error happen on?
Member 10194266 5-Jul-19 9:59am    
in below code

invClient.SendrequestToSL(arrList.ToArray())

1 solution

C#
        public string SendrequestToSL(List<InvReqClass> ListInvReqClass)

// ...


        Dim arrList As New System.Collections.ArrayList(listReq)
        invClient.SendrequestToSL(arrList.ToArray())

The SendrequestToSL method clearly requires a parameter of type List<InvReqClass>, but you are passing a simple array.
 
Share this answer
 
Comments
Member 10194266 5-Jul-19 10:01am    
Hi Richard ,

Can you write a code which code i should used
Richard MacCutchan 5-Jul-19 15:15pm    
Seriously, all you need to do is to pass the correct list type as defined by the method signature.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900