title: Null Reference Exception in line checking for Null?
body: <p>I have a fairly simple piece of code:</p>
  
  <pre><code>Private _PurchaseDelivery as PurchaseDelivery
  
  Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As PurchaseDeliveryItem)
      Dim SKUBin As SKUBin
      If _PurchaseDelivery IsNot Nothing AndAlso _PurchaseDelivery.DefaultSKUBinID.HasValue Then
          SKUBin = item.StockOrderUnit.SKU.SKUBins.GetByBinID(_PurchaseDelivery.DefaultSKUBinID.Value)
          item.SKUBin = SKUBin
      End If
  
      MyBase.InsertItem(index, item)
  End Sub
  </code></pre>
  
  <p>Which is inside a class which overrides a custom list base. The code is occassionaly throwing an unhandled exception, <code>System.NullReferenceException</code>, on this line when used in production:</p>
  
  <pre><code>    If _PurchaseDelivery IsNot Nothing AndAlso _PurchaseDelivery.DefaultSKUBinID.HasValue Then
  </code></pre>
  
  <p>DeafultSKUBinID is declared as an <code>Integer?</code> (Nullable Int) in the <code>PurchaseDelivery</code> class. I cannot see what might be causing this error, why would this be returning an error?</p>