title: Disable null reference warning when I've checked for nulls
body: <p>In the following code, if <code>cmd</code> has been initialized, then I'll make to sure to close any open connections before throwing an exception. However, even after I check that <code>cmd</code> is not null, I still get a possible null reference warning in subsequent lines of code.</p>
  <pre class="lang-vb prettyprint-override"><code>Dim cmd As SqlCommand
  Try
      'Do some Stuff
  Catch ex As Exception
      If cmd IsNot Nothing AndAlso
         cmd.Connection IsNot Nothing AndAlso              '&lt;- null cmd warning 
         cmd.Connection.State = ConnectionState.Open Then  '&lt;- null cmd warning 
          cmd.Connection.Close()                           '&lt;- null cmd warning 
      End If
      Throw
  End Try
  </code></pre>
  <p>I get the two following warnings (possibly one from Resharper &amp; one from Visual Studio):</p>
  <blockquote>
  <ul>
  <li>Variable 'x' might not be initialized before accessing.  A null reference exception could occur at runtime.</li>
  <li>BC42104: Variable 'x' is used before it has been assigned a value. A null reference exception could result at runtime.</li>
  </ul>
  </blockquote>
  <p>According to the <a href="http://msdn.microsoft.com/en-us/library/3fdk625a.aspx" rel="nofollow noreferrer">Visual Studio Page</a>:</p>
  <blockquote>
  <p>An application has at least one possible path through its code that reads a variable before any value is assigned to it.</p>
  </blockquote>
  <p>But I don't think there is even one possible path through the code where the variable would be used without being initialized.</p>
  <ul>
  <li>Have I made some error or is this a bug?</li>
  <li>Is there a way to disable this warning from coming up?</li>
  </ul>
  <p>Here's a screenshot:</p>
  <p><img src="https://i.imgur.com/fLZPwdb.png" alt="screenshot" /></p>
  <p>This is different from many similar questions already asked here, like <a href="https://stackoverflow.com/q/5172674/1366033">Prevent Resharper “Possible Null Reference Exception” warnings</a> because I'm not trying to allow for a NullableType, but instead have already guaranteed that my variable is not null.</p>
  <hr />
  <h2>Update:</h2>
  <p>Follow up question: Why?</p>
  <p>Whether my object is never initialized or initialized to <code>Nothing</code>, in both cases <code>cmd IsNot Nothing</code> should resolve to <code>False</code>, so anything after the <code>AndAlso</code> should never be executed.</p>
  <pre class="lang-vb prettyprint-override"><code>Dim cmd1 As SqlCommand
  Console.Write(cmd1 IsNot Nothing) 'False
  
  Dim cmd2 As SqlCommand = Nothing
  Console.Write(cmd2 IsNot Nothing) 'False
  </code></pre>
  <p>Maybe the compiler just doesn't have a good way of guaranteeing this at compile time.</p>