title: Problems using classes in vb.net
body: <p>I am implementing a procedure for creating an XML file for the transmission of some data, using VS 2019 vb.net.
  To do this, I have built a series of classes as suggested by Microsoft. The procedure compiles correctly but at run time generates an error like 'Object reference not set on an object instance.' to the line</p>
  <pre><code>FileAbaco.utenti(0).utente(0).strutture(0).struttura.Add(stra)
  </code></pre>
  <p>I can't understand where I'm wrong. Thank you in advance for any help you will be able to provide.</p>
  <pre><code>Dim FileAbaco As New dichiarazioni
          FileAbaco.comune = &quot;I608&quot;
          Dim uti As New utenti
          FileAbaco.utenti.Add(uti)
          Dim ute As New utente
          FileAbaco.utenti(0).utente.Add(ute)
          Dim stre As New strutture
          FileAbaco.utenti(0).utente(0).strutture.Add(stre)
          Dim stra As New struttura
          FileAbaco.utenti(0).utente(0).strutture(0).struttura.Add(stra)
          Dim dr As DataRow
          dr = DTTrimestrale.Rows(0)
          With FileAbaco.utenti(0).utente(0)
              .auth = dr.Item(&quot;auth&quot;.ToString)
              .gest_codice_fiscale = dr.Item(&quot;gest_codice_fiscale&quot;)
              .codice_utente = dr.Item(&quot;codice_utente&quot;)
              .gest_cognome = dr.Item(&quot;gest_cognome&quot;)
              .gest_nome = &quot;&quot;
          End With
  </code></pre>
  <p>These are the classes:</p>
  <pre><code>Imports System.Xml.Serialization
  
  Public Class dichiarazioni
      Public comune As String
      &lt;XmlElement()&gt;
      Public Property utenti As New List(Of utenti)
  End Class
  
  Public Class utenti
      &lt;XmlElement()&gt;
      Public Property utente As New List(Of utente)
  End Class
  
  Public Class utente
      Public Property auth As String
      Public Property gest_codice_fiscale As String
      Public Property codice_utente As String
      Public Property gest_cognome As String
      Public Property gest_nome As String
      Public Property strutture As New List(Of strutture)
      Public Sub New()
  
      End Sub
  
      Public Sub New(auth As String, gest_codice_fiscale As String, codice_utente As String, gest_cognome As String, gest_nome As String, strutture As strutture)
          Me.auth = auth
          Me.gest_codice_fiscale = gest_codice_fiscale
          Me.codice_utente = codice_utente
          Me.gest_cognome = gest_cognome
          Me.gest_nome = gest_nome
          Me.strutture.Add(strutture)
      End Sub
  End Class
  Public Class strutture
      &lt;XmlElement()&gt;
      Public Property struttura As List(Of struttura)
      Public Sub New()
  
      End Sub
      Public Sub New(struttura As struttura)
          Me.struttura.Add(struttura)
      End Sub
  End Class
  Public Class struttura
      &lt;XmlElement()&gt;
      Public Property ID_struttura As String
      Public Property insegna As String
      Public Sub New()
  
      End Sub
      Public Sub New(ID_struttura As String, insegna As String)
          Me.ID_struttura = ID_struttura
          Me.insegna = insegna
      End Sub
  End Class
  
  </code></pre>