title: VB.NET LINQ query on List(Of Object)
body: <p>I am having trouble with a LINQ query -</p>
  
  <pre><code> Dim otherRecords As List(Of Objects) = listOf.Where(Function(x) x.ID_NUM = newID _
                                          And (x.Codes.Contains(ddlPrimaryCode.SelectedItem.Text.Trim) And Not x.Codes = Nothing)).ToList()
  </code></pre>
  
  <p><strong>Error</strong> An exception of type 'System.NullReferenceException' occurred in CI.dll but was not handled in user code</p>
  
  <p>Additional information: Object reference not set to an instance of an object.</p>
  
  <p>The problem is the <strong>listOf</strong> contains the value "Nothing" for the x.Codes.Contains.</p>
  
  <p>Before I had </p>
  
  <pre><code> Dim otherRecords As List(Of Objects) = listOf.Where(Function(x) x.ID_NUM = newID _
                                                         And (x.Codes.Contains(ddlPrimaryCode.SelectedItem.Text.Trim)).ToList()  
  </code></pre>
  
  <p>And it was crapping out.</p>
  
  <p>I need to be able to return only records with matching ID_NUM and Codes.</p>