When I write something like this:
using (var connection = new SqlConnection("ConnectionString"))
{
using(var cmd= new SqlCommand("Command"))
{
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
}
}
}
}
ReSharper shows warning on reader.Read(), and tells that reader can be null.
But in what cases can it be null? As I know if command returns nothing reader is not null, it only have nothing.
Given that this is reported on YouTrack as a bug (twice – here and here), it looks like the nullity annotations that are shipped with R# are deficient in this respect.
Have a look in your
ReSharper_installation_dir\Bin\ExternalAnnotationsfolder – this is where the annotations files get installed. For me, with v5, there is in here a fileSystem.Data\System.Data.Nullness.xmlwhich contains this annotation:If by your own inspection you are satisfied that this is wrong, and that
SqlCommand.ExecuteReadernever returns null, you should change this to