Object not set to instance error when trying to instance object.

UnderSeven
UnderSeven used Ask the Experts™
on
Here is my code
 Dim objXMLHTTP As New MSXML2.ServerXMLHTTP60()


            Dim service As New pconWSService.pconWSService
            Dim response As New pconWSService.InitiateSessionTransferResponse
            Dim initiatePublicSessionTransferRequest As New pconWSService.InitiatePublicSessionTransferRequest

            initiatePublicSessionTransferRequest.parameters(0) = New pconWSService.Parameter With {.name = "StatementNo", .value = Session.Item("curStatement")}

Open in new window


The last line is throwing the object refernce not set error.

This is the object definition:

 Partial Public Class Parameter
        
        Private nameField As String
        
        Private valueField As String
        
        '''<remarks/>
        Public Property name() As String
            Get
                Return Me.nameField
            End Get
            Set
                Me.nameField = value
            End Set
        End Property

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Hi UnderSeven;

Where is the rest of the Parameter class?

Are you sure that you have a value in Session.Item("curStatement") ?

Author

Commented:
Here is the entire class.  For the sake of simplicity I've hard coded that value,

       initiatePublicSessionTransferRequest.parameters(0) = New pconWSService.Parameter With {.name = "StatementNo", .value = "1"}

    Partial Public Class Parameter
        
        Private nameField As String
        
        Private valueField As String
        
        '''<remarks/>
        Public Property name() As String
            Get
                Return Me.nameField
            End Get
            Set
                Me.nameField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property value() As String
            Get
                Return Me.valueField
            End Get
            Set
                Me.valueField = value
            End Set
        End Property
    End Class

Open in new window

Fernando SotoRetired
Distinguished Expert 2017

Commented:
In the initiatePublicSessionTransferRequest object has the parameters array been created and initialized?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Author

Commented:
It's part of the initiatepublictransferrequest class.  I thought, here is that definition.

I assumed I was missing something obvious.

 Partial Public Class InitiatePublicSessionTransferRequest
        
        Private billerGroupIdField As String
        
        Private billerIdField As String
        
        Private productCodeField As String
        
        Private billerPayorIdField As String
        
        Private amountDueField As System.Nullable(Of Decimal)
        
        Private amountDueTbdField As Boolean
        
        Private dueDateField As System.Nullable(Of Date)
        
        Private dueDateTbdField As Boolean
        
        Private level2SalesTaxAmountField As System.Nullable(Of Decimal)
        
        Private level2CustomerReferenceNumberField As String
        
        Private userIdField As String
        
        Private localeField As String
        
        Private parametersField() As Parameter
        
        Private disallowLoginField As System.Nullable(Of Boolean)
        
        Private returnSessionIdField As String
        
        Private returnUrlField As String
        
        '''<remarks/>
        Public Property billerGroupId() As String
            Get
                Return Me.billerGroupIdField
            End Get
            Set
                Me.billerGroupIdField = value
            End Set
        End Property
        
        '''<remarks/>
        Public Property billerId() As String
            Get
                Return Me.billerIdField
            End Get
            Set
                Me.billerIdField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property productCode() As String
            Get
                Return Me.productCodeField
            End Get
            Set
                Me.productCodeField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property billerPayorId() As String
            Get
                Return Me.billerPayorIdField
            End Get
            Set
                Me.billerPayorIdField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property amountDue() As System.Nullable(Of Decimal)
            Get
                Return Me.amountDueField
            End Get
            Set
                Me.amountDueField = value
            End Set
        End Property
        
        '''<remarks/>
        Public Property amountDueTbd() As Boolean
            Get
                Return Me.amountDueTbdField
            End Get
            Set
                Me.amountDueTbdField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(DataType:="date", IsNullable:=true)>  _
        Public Property dueDate() As System.Nullable(Of Date)
            Get
                Return Me.dueDateField
            End Get
            Set
                Me.dueDateField = value
            End Set
        End Property
        
        '''<remarks/>
        Public Property dueDateTbd() As Boolean
            Get
                Return Me.dueDateTbdField
            End Get
            Set
                Me.dueDateTbdField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property level2SalesTaxAmount() As System.Nullable(Of Decimal)
            Get
                Return Me.level2SalesTaxAmountField
            End Get
            Set
                Me.level2SalesTaxAmountField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property level2CustomerReferenceNumber() As String
            Get
                Return Me.level2CustomerReferenceNumberField
            End Get
            Set
                Me.level2CustomerReferenceNumberField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property userId() As String
            Get
                Return Me.userIdField
            End Get
            Set
                Me.userIdField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property locale() As String
            Get
                Return Me.localeField
            End Get
            Set
                Me.localeField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlArrayAttribute(IsNullable:=true),  _
         System.Xml.Serialization.XmlArrayItemAttribute("parameter", IsNullable:=false)>  _
        Public Property parameters() As Parameter()
            Get
                Return Me.parametersField
            End Get
            Set
                Me.parametersField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property disallowLogin() As System.Nullable(Of Boolean)
            Get
                Return Me.disallowLoginField
            End Get
            Set
                Me.disallowLoginField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property returnSessionId() As String
            Get
                Return Me.returnSessionIdField
            End Get
            Set
                Me.returnSessionIdField = value
            End Set
        End Property
        
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)>  _
        Public Property returnUrl() As String
            Get
                Return Me.returnUrlField
            End Get
            Set
                Me.returnUrlField = value
            End Set
        End Property
    End Class

Open in new window

Retired
Distinguished Expert 2017
Commented:
You defined an array in the class but from what you have posted so far you have NOT created an instance of the array parameter.

''' Excerpts from your code
Private parametersField() As Parameter

'''<remarks/>
<System.Xml.Serialization.XmlArrayAttribute(IsNullable:=true),  _
System.Xml.Serialization.XmlArrayItemAttribute("parameter", IsNullable:=false)>  _
        Public Property parameters() As Parameter()
            Get
                Return Me.parametersField
            End Get
            Set
                Me.parametersField = value
            End Set
End Property

Open in new window


Somewhere you need to instantiate the array

Author

Commented:
Wouldn't this in theory instantiate the array:

Dim initiatePublicSessionTransferRequest.parameters() as pconWSService.Parameter

initiatePublicSessionTransferRequest.parameters = New pconWSService.Parameter() With {.name = "StatementNo", .value = Session.Item("curStatement")}

But it is tellig me exepecting end of statement on the dim statement and on the latter statement that it can't convert pconWSService.parameter() to a one dimiensional array.  

I'm still confused what I'm doing wrong.
Fernando SotoRetired
Distinguished Expert 2017

Commented:
On what line are you getting the exception? Please also post the exception and inner exception messages.

Author

Commented:
Dim initiatePublicSessionTransferRequest.parameters() as InitiatePublicSessionTransferRequest.parameters

First bolded: end of statement expected

It won't compile at this poitn so I can't give inner exceptions.

Author

Commented:
This is the solution.  More or less what you said it would be.

Dim initiatePublicSessionTransferRequest As pconWSService.InitiatePublicSessionTransferRequest = New pconWSService.InitiatePublicSessionTransferRequest


                Dim paramfields(0) As pconWSService.Parameter

                paramfields(0) = New pconWSService.Parameter With {.name = "StatementNo", .value = Session.Item("curStatement")}

                initiatePublicSessionTransferRequest.parameters = paramfields

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial