-
Notifications
You must be signed in to change notification settings - Fork 227
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
Fix S3881: "Implement IDisposable correctly" should allow calling GC.SuppressFinalize(this) even when there is no destructor #530
Comments
It is complaining because you have |
You are right, that removing When the class is not sealed, it has to call Actually, when the class is not |
You are right, we are too strict here. Even though I personally don't like deep class hierarchies, adding a finalizer in a subclass is a valid scenario, and S3881 is exactly about extensibility of IDisposable implementations. We will discuss and fix that. Thanks a lot for the feedback! |
The fixed implementation, following Microsoft CA1816 and CA1063, is however wrong as I wrote here: Adding CG.SuppressFinalize will not harm since
but this is just useless: every .NET developer dealing mostly with managed code is adding a line of code for nothing in his code. IMHO, it would be much better to detect if the class has a finalizer, and if no finalizer, do not ask for SuppressFinalize ! |
Description
I am following the basic dispose pattern (https://docs.microsoft.com/en-GB/dotnet/standard/design-guidelines/dispose-pattern) but I am getting violation of the rule S3881. Even in the SonarLint documentation it seems that it is implemented correctly.
Repro steps
The following code triggers the issue:
Expected behavior
I would expect no error reported.
Actual behavior
Error about rule S3881.
Known workarounds
When I change the class to sealed then it is fine. It happened in .NET Core project with target framework: .NET Standard 1.4.
Related information
The text was updated successfully, but these errors were encountered: