I'm trying to populate class properties where one property is a list collection. I get a NullReferenceException when trying to add to the list collection. The code (litlle bit simplified) is here:
I have a nested class "Asset" inside the class "Portfolio"
Everything goes ok until the line
Which gives me the NullReferenceException error.
Where's the problem?
VB.NET:
Public Class Portfolio
Property Name As String
Property Assets As List(Of Asset)
Public Sub Populate(ByVal data As DataTable)
For Each row As DataRow In data.Rows
Dim asset As New Asset(CStr(row.Item("AssetName")))
With asset
.AssetID = CStr(row.Item("AssetNo"))
.Value = CDec(CStr(row.Item("MarketValue")))
End With
Me.Assets.Add(asset)
Next
End Sub
Public Class Asset
'properties here...
End Class
End Class
I have a nested class "Asset" inside the class "Portfolio"
Everything goes ok until the line
VB.NET:
Me.Assets.Add(asset)
Where's the problem?