I am getting code analysis error for not disposing dataset. This arises when I passed DataSet as argument to method Test2. when I am commenting call to Test2(), this error got remove. So please help me out to resolve this error.
static DataSet TestMethod(DataSet s)
{
try
{
try
{
if (s != null)
{
s = new DataSet();
//some other stuff....
}
**s = Test2(s);** //This line causes Dispose code analysis error
}
catch (InvalidCastException)
{
throw;
}
return s;
}
catch (Exception)
{
throw;
}
finally
{
if (s!=null)
{
s.Dispose();
}
}
}
static DataSet Test2(DataSet s)
{
try
{
//some stuff
}
catch (InvalidCastException)
{
}
finally
{
s.Dispose();
}
return s;
}