Reputation: 4655
I have problem with assigning values to a defined class members. Classes OutgoingInvoicesData and OutgoingInvoicesDataHeader are automatically created from XML and are reachable through InteliSense.
So, what do I missed here or what do I doing wrong and how can I instantiate a class and assign values to its members without getting an error in order to serialize and deserialize it's data?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim oid As OutgoingInvoicesData = New OutgoingInvoicesData()
oid.Header.SupplierID = 26742352147 'Here: Object reference not set to an instance of an object.
oid.Header.InvoiceType = 1
End Sub
End Class
<System.SerializableAttribute()>
<System.ComponentModel.DesignerCategoryAttribute("code")>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://mypage/OutgoingInvoicesData/v3.2")>
<System.Xml.Serialization.XmlRootAttribute([Namespace]:= "http://mypage/OutgoingInvoicesData/v3.2", IsNullable:=False)>
Partial Public Class OutgoingInvoicesData
Private headerField As OutgoingInvoicesDataHeader
Public Property Header As OutgoingInvoicesDataHeader
Get
Return Me.headerField
End Get
Set(ByVal value As OutgoingInvoicesDataHeader)
Me.headerField = value
End Set
End Property
End Class
<System.SerializableAttribute()>
<System.ComponentModel.DesignerCategoryAttribute("code")>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://mypage/OutgoingInvoicesData/v3.2")>
Partial Public Class OutgoingInvoicesDataHeader
Private supplierIDField As ULong
Private invoiceTypeField As Byte
Public Property SupplierID As ULong
Get
Return Me.supplierIDField
End Get
Set(ByVal value As ULong)
Me.supplierIDField = value
End Set
End Property
Public Property InvoiceType As Byte
Get
Return Me.invoiceTypeField
End Get
Set(ByVal value As Byte)
Me.invoiceTypeField = value
End Set
End Property
End Class
Upvotes: 0
Views: 335
Reputation: 82
The property 'Header' is Nothing when initializing your class, so you cannot assign a value to its 'SupplierID'.
Change
Private headerField As OutgoingInvoicesDataHeader
to
Private headerField As New OutgoingInvoicesDataHeader
Upvotes: 1