Link to home
Start Free TrialLog in
Avatar of LEONEL ROCHA
LEONEL ROCHAFlag for Uruguay

asked on

Getting "Object reference not set to an instance of an object" when loading structured data info into a webreference array. Something is missing in my code?

I have a collection of structured data to load into a web reference from a SOAP service.
When I try to load each element of the collection into one of the web reference structures I get the message "Object reference not set to an instance of an object".
I know what the error is due to, but surely I have something wrong defined or undefined (initializing perhaps) and I can't find it.
Here is an example of the code (the line with bold characters is where the error is reported):


'--- my data structures
Public Structure MyPaymentSDT
    Public externalId As String
    Public CustCode As String
    Public ExpirationRequest As String
    Public CurrCode As String
    Public reference As String
    Public products As String
    Public items As String
End Structure
Public Structure MyPaymentItemSDT
    Public code As String
    Public description As String
    Public qty As Decimal
    Public ammount As Decimal
    Public taxPercent As Decimal
End Structure


'--- webservice reference examples

'APStartReqWebRefce.requestDTO 

'custCode as string

'currCode as string

'detaileditems As WSAPPayments.APStartReqWebRefce.requestdetaileditem

'

'APStartReqWebRefce.requestdetaileditem

'items As WSAPPayments.APStartReqWebRefce.requestitem()

'

'APStartReqWebRefce.requestitem

'itmCode as string

'itmDesc as string

'itmQty as decimal

'itmAmmount as decimal

'itmTaxPercent as decimal


'--- my definitions
Dim Pmt As New MyPaymentSDT
Dim PmtEachItem As New MyPaymentItemSDT
Dim PmtListItem As New List(Of MyPaymentItemSDT)

'--- external web reference SOAP
Dim wbrSolicDto As New APStartReqWebRefce.solicitudDTO
Dim wbrSolicItems As APStartReqWebRefce.solicituditem()

Try
    '--- upload my XML info into my data structure
    Pmt = DirectCast(XMLToStruct(mypmt, GetType(MyPaymentSDT)), MyPaymentSDT)
    PmtListItem = DirectCast(XMLToStruct(Pmt.items, GetType(List(Of MyPaymentItemSDT))), List(Of MyPaymentItemSDT))

    '--- load every item in my list to web service reference list
    Dim CounterItm As Integer = 0
    ReDim Preserve wbrSolicItems(PmtListItem.Count)
    For Each PmtEachItem In PmtListItem
        CounterItm += 1
        wbrSolicItems(CounterItm - 1).itmCode = PmtEachItem.code
        wbrSolicItems(CounterItm - 1).itmDesc = PmtEachItem.description
        wbrSolicItems(CounterItm - 1).itmQty = PmtEachItem.qty
        wbrSolicItems(CounterItm - 1).itmAmmount = PmtEachItem.ammount
        wbrSolicItems(CounterItm - 1).itmTaxPercent = PmtEachItem.taxPercent
    Next
    wbrSolicDto.detalleitems.items = wbrSolicItems
....

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Andy is correct.  if the type is a base type, it gets created automatically.
for an object, you have to create the object and assign that to an array element. then access the properties.


Avatar of LEONEL ROCHA

ASKER

OMG!, I am ashamed.

Thanks so much!