We have following observation:
- IDisposables created by static factory methods should be reported as S2930.
- We are using: Data Center Edition * Version 10.1 (build 73491)
Following code produces a S2930:
FileStream s = new FileStream("D:\\TEST", FileMode.Open);
whereas this code does not report S2930:
FileStream s = File.OpenRead("D:\\TEST");
Thank you for reporting this issue!
S2930 is indeed not reporting in this example. I confirm this as an FN and I have opened a ticket in our repository
To give some info, it is stated in the rule description, that we cover a predefined list of factory method that we check:
File.OpenRead is not part of the list, it is “expected” for S2930 to not report.
Have a nice end of the day!
Thanks for the feedback. I have also opened a request on the dotnet/runtime to mark methods explicitly so that these things can be discovered: [API Proposal]: Possibility to check if a return value needs to be disposed. · Issue #94832 · dotnet/runtime (github.com)