Detect Use of Unmanaged Resources
Hi,
I am completely new to FXCop so sorry if this is a dumb question, but could FXCop detect when an class creates an object that uses unmanaged resources, that does cleanup properly, something likepublicvoid CreateMemoryStreamUnmanaged()
{
MemoryStream memStream =new MemoryStream(100);
memStream.Position=0L;
Console.WriteLine("Created Memory Stream " + i);
++i;
}
So, it would say that I have created an object that uses unmanaged resources and should be cleaned up using using statement or finally block etcThanks
[871 byte] By [
Lenin] at [2008-2-11]
If you know what objects you want to tag then yes, it's do-able. I've just written some in-house rules that ensure that all SqlDataReader, StreamWriter and StreamReader objects are used as part of a using() block.
There's no 'easy' way to do this - you have to analyse IL patterns and tag occurances that don't fit your design pattern, so get ILDSM loaded!
Regards,
James.
We do have a rule that performs this analysis but it will not ship until the next FxCop update. We don't currently have a time-frame for this, it's not clear whether we'll be doing a small patch soon (that simply ships 4 new rules) or waiting for the next major dot release (which would not occur until two or three months from now at the earliest).
This forum, of course, is exactly the right place to monitor for more information,
Michael Fanning
VSTS Development: Code Analysis