R
Raymon
This is driving me nuts.
I have a emthod that returns a DataTable.
The outline of the mothod is as follows:
public DataTable MyMethod(<argument list>)
{
DataTable dt = null;
try
{
dt = new DataTable;
(code to add columns to dt)
(Do lots of stuff)
return dt;
}
finally
{
if (dt != null)
dt.Dispose();
}
There is no catch block as the caller will handle any exceptions.
When I run code analysis I get the warning to the effect:
"call dispose on objec dt befor all references to it are out of scope"
There are several places in the try block (other than at the end)
where the code exits with a return dt.
But no matter what happens in the try block, even if an exception
occurs, the finally executes.
Isn't that correct?
Then why is it giving this warning?
The curious thing is that I use the same method of dispose in other
methods and they don't generate this warning.
P.S. Don't ask for the code as it is too long.
I have a emthod that returns a DataTable.
The outline of the mothod is as follows:
public DataTable MyMethod(<argument list>)
{
DataTable dt = null;
try
{
dt = new DataTable;
(code to add columns to dt)
(Do lots of stuff)
return dt;
}
finally
{
if (dt != null)
dt.Dispose();
}
There is no catch block as the caller will handle any exceptions.
When I run code analysis I get the warning to the effect:
"call dispose on objec dt befor all references to it are out of scope"
There are several places in the try block (other than at the end)
where the code exits with a return dt.
But no matter what happens in the try block, even if an exception
occurs, the finally executes.
Isn't that correct?
Then why is it giving this warning?
The curious thing is that I use the same method of dispose in other
methods and they don't generate this warning.
P.S. Don't ask for the code as it is too long.