I originally reported this here https://github.com/MicrosoftDocs/visualstudio-docs/issues/734#issuecomment-375765639 and was asked to post it here.
Put this code in a C# UWP app
{
var tempFolder = ApplicationData.Current.TemporaryFolder;
var filename = Guid.NewGuid().ToString();
var tmpFile = await tempFolder.CreateFileAsync(filename, CreationCollisionOption.GenerateUniqueName);
// Expect a warning that stream is not disposed
var stream = await tmpFile.OpenAsync(FileAccessMode.ReadWrite);
var dw = new DataWriter(stream);
dw.WriteString("New file");
// stream.Dispose();
}
Run code analysis with all rules turned on.
Warning CA2000 should be emitted
No warning.
Thank you @phraemer. I will investigate.
@phraemer Do you happen to remember if there was a throw on your method?
@mavasani I have created a UWP application and tried the code snippet mentioned and I have noticed that the issue was correctly raised. Although, doing some more tests, I have noticed that if there is an unconditional throw statement in the method then the analysis is stopped and no issue is reported (regardless of the type of the project). This looks like a limitation of the CFG or dataflow but I will need to investigate a bit more. Shall we close this ticket and create a new one for the issue with the throw?
@Evangelink I don't think there was a throw. However, I just tried the FxCop analyzers since the binary analyzers seem to have been deprecated and it picks up the lack of a call to dispose. So from my point of view we could consider this closed.
Thank you for the feedback.
Thanks!