2016-08-15 58 views
0

好的,恐怕我对这个有点失落。以下代码给出了CA 2000警告:“'新WebRequestHandler()'没有沿着所有异常路径放置”。WebRequestHandler给出了奇数的一次性使用警告

this.webHandler = new WebRequestHandler() 
{ 
    AllowAutoRedirect = true, 
    AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, 
    CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache), 
    CookieContainer = cookies, 
    ReadWriteTimeout = 5000 
}; 

我与挣扎了好20分钟发现什么我相信在功能上是相同的代码不给同样的警告之前。

this.webHandler = new WebRequestHandler(); 
this.webHandler.AllowAutoRedirect = true; 
this.webHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; 
this.webHandler.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); 
this.webHandler.CookieContainer = cookies; 
this.webHandler.ReadWriteTimeout = 5000; 

显然,解决方案是使用后一种方法(或只是抑制警告),但有蹊跷的是,我只是不知道第一种方式?

+0

[使用对象初始值设定项生成CA 2000警告]的可能重复(http://stackoverflow.com/questions/8739065/using-object-initializer-generates-ca-2000-warning) – RobinHood70

回答