IDISP001 does not take into account factories
See original GitHub issueWarning IDISP001 Dispose created.
As per this Stack Overflow discussion factories should not keep track of created IDisposable
objects. This disagrees with the explanation for the analyzer rule:
When you create an instance of a type that implements IDisposable you are responsible for disposing it.
Following on from this you can see for rule CA2000:
Do not suppress a warning from this rule unless: The allocating method does not have dispose ownership; that is, the responsibility to dispose the object is transferred to another object or wrapper that’s created in the method and returned to the caller
The reproduction is the code in the original question.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It also does not take into account
Form.FindForm()
too on winforms and then says “you must wrap this in a using block”, however doing that would close the form instead which is not always intended at all.I think the analyzer should check and see if it is from a call to
FindForm()
on any class that inherits fromControl
on Windows Forms and then ignore it and not warn.Done: https://github.com/DotNetAnalyzers/IDisposableAnalyzers/issues/286