<p>There is probably is simple fix for this but I currently have code similar to </p>

<pre><code>dim dr as dbDataReader

try
      dr = connection.getDataReader(sql_str)
Catch ex as sqlClientException
     log.error(ex)
finally 

  if not IsNothing(dr) then
    dr.close
  end if
end try
</code></pre>

<p>However Visual Studio still warns me that the </p>

<pre><code>if not IsNothing(dr) then
        dr.close
      end if
</code></pre>

<p>Can cause a NullReferenceException. What is the best way to mitigate this? I can't move the declaration into the try block.</p>

Your code is correct. In the
```
finally
```
statement, as long as you check to make sure your objects are not null, it won't throw a null reference exception based on what happens in your code.