Click here to Skip to main content
14,386,394 members
Rate this:
Please Sign up or sign in to vote.
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 5-Jul-19 0:39am
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

        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.
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100