Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dispose rules on non-shipping projects in Roslyn.sln #25129

Open
mavasani opened this issue Feb 28, 2018 · 0 comments
Open

Enable dispose rules on non-shipping projects in Roslyn.sln #25129

mavasani opened this issue Feb 28, 2018 · 0 comments

Comments

@mavasani
Copy link
Member

mavasani commented Feb 28, 2018

We are currently planning to move Roslyn.sln to dogfood the latest analyzers package that has couple of DFA based dispose rules. More specifically we are enabling the following rules:

  1. CA2000 (Dispose objects before losing scope): A local object of a IDisposable type is created but the object is not disposed before all references to the object are out of scope.
  2. CA2213 (Disposable fields should be disposed): A type that implements System.IDisposable declares fields that are of types that also implement IDisposable. The Dispose method of the field is not called by the Dispose method of the declaring type.

A disposable object created in a method body, which is not saved into an instance field and/or escaped via either calling into an external library or returned by the method, must be disposed in a method. If assigned to a field of a disposable object, then the Dispose/DisposeBool/Close method (or call graph rooted at this method) of the containing type must dispose the field. If escaped via returning the disposable object, then the caller takes over the ownership to dispose the object.

These rules have large number of violations in non-shipping projects. These are either real dispose leaks that need to be fixed or false positives that must be suppressed. For now, we are disabling this rule in the non-shippin projects by adding entries to NonShippingProject_BuildRules.ruleset. This issue tracks removing these ruleset entries, and fixing/suppressing the dispose violations in non-shipping projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant