Resharper: Possible null assignment to entity marked with notnull attribute

后端 未结 3 2129
梦谈多话
梦谈多话 2021-01-01 10:28

I get this warning on response.GetResponseStream() How should I handle this?

// Get response  
using (var response = request.GetResponse() as Ht         


        
3条回答
  •  粉色の甜心
    2021-01-01 11:25

    var reader = new StreamReader(response.GetResponseStream());
    

    I suspect StreamReader constructor's parameter has a notnull attribute. Try the following:

    var stream = response.GetResponseStream();
    if (stream == null)
      // throw an exception
    var reader = new StreamReader(stream);
    

提交回复
热议问题