本文介绍了ReSharper的:可能空分配给实体打上NOTNULL属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到 response.GetResponseStream此警告()
我应该如何处理呢?
//使用(VAR响应= request.GetResponse()作为HttpWebResponse)
{
//获取响应流
获得响应
如果(响应!= NULL)
{
变种读者=新的StreamReader(response.GetResponseStream());
VAR responseString = reader.ReadToEnd();
返回responseString;
}
}
为了清楚起见基于一些答案曲解
这行的不可以那里的警告正在发生:
使用(VAR响应= request.GetResponse()作为HttpWebResponse)
此行的是其中警告正在发生:
VAR读者=新的StreamReader(响应。 GetResponseStream());
解决方案
VAR读者=新的StreamReader(response.GetResponseStream());
我怀疑的StreamReader
构造函数的参数有一个 NOTNULL
属性。请尝试以下操作:
VAR流= response.GetResponseStream();
如果(流== NULL)
//抛出一个异常
变种读者=新的StreamReader(流);
I get this warning on response.GetResponseStream()
How should I handle this?
// Get response
using (var response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
if (response != null)
{
var reader = new StreamReader(response.GetResponseStream());
var responseString = reader.ReadToEnd();
return responseString;
}
}
For clarity based on some answers misinterpreting:
This line is not where the warning is occurring:
using (var response = request.GetResponse() as HttpWebResponse)
This line is where the warning is occurring:
var reader = new StreamReader(response.GetResponseStream());
解决方案
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);
这篇关于ReSharper的:可能空分配给实体打上NOTNULL属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!