I have a code
public String makeHttpGetRequest(String url)
{
try
{
string responce = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
responce = reader.ReadToEnd();
}
return responce;
}
catch (Exception e)
{
Console.WriteLine("Internet Connection error" + e.Message);
return null;
}
}
And i am getting a warning when i run code analysis in Visual studio that
CA2202 Do not dispose objects multiple times Object 'stream' can be disposed more than once in method 'InformationIO.makeHttpGetRequest(string)'. To avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an object.: Lines: 244 InformationIO.cs 244
line 224 refers to line 13 here the closing bracket before return responce;
How can i fix this warning.