When would SqlCommand.ExecuteReader() return null?

后端 未结 5 851
孤城傲影
孤城傲影 2020-12-11 15:52

When using calling the SqlCommand.ExecuteReader() method, ReSharper tells me I have a possible NullReference exception when I use the SqlDataReader object after

5条回答
  •  鱼传尺愫
    2020-12-11 16:27

    It's a false positive.

    Reflecting on SqlDataReader.ExecuteReader, I can see that the only way the reader is returned as null is if the internal RunExecuteReader method is passed 'false' for returnStream, which it isn't.

    In the depths of SqlDataReader, a reader constructor is always called at some point, so I'm pretty sure this is not physically possible for ExecuteReader to return null.

提交回复
热议问题