You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`IDisposable`is not implemented correctly. Some reasons for this problem are listed here:
33
+
The <xref:System.IDisposable?displayProperty=nameWithType> interface is not implemented correctly. Possible reasons for this include:
32
34
33
-
- IDisposable is re-implemented in the class.
35
+
-<xref:System.IDisposable> is reimplemented in the class.
34
36
35
-
- Finalize is re-overridden.
37
+
- Finalize is reoverridden.
36
38
37
-
- Dispose is overridden.
39
+
- Dispose() is overridden.
38
40
39
-
- Dispose() is not public, sealed, or named Dispose.
41
+
-The Dispose() method is not public, [sealed](/dotnet/csharp/language-reference/keywords/sealed), or named **Dispose**.
40
42
41
43
- Dispose(bool) is not protected, virtual, or unsealed.
42
44
43
45
- In unsealed types, Dispose() must call Dispose(true).
44
46
45
-
- For unsealed types, the Finalize implementation does not call either or both Dispose(bool) or the case class finalizer.
47
+
- For unsealed types, the Finalize implementation does not call either or both Dispose(bool) or the base class finalizer.
46
48
47
-
Violation of any one of these patterns will trigger this warning.
49
+
Violation of any one of these patterns triggers warning CA1063.
48
50
49
-
Every unsealed type that declares and implements the IDisposable interface must provide its own protected virtual void Dispose(bool) method. Dispose() should call Dipose(true) and Finalize should call Dispose(false). If you are creating an unsealed type that declares and implements the IDisposable interface, you must define Dispose(bool) and call it. For more information, see [Cleaning up unmanaged resources](/dotnet/standard/garbage-collection/unmanaged)in the [.NET Framework design guidelines](/dotnet/standard/design-guidelines/index).
51
+
Every unsealed type that declares and implements the <xref:System.IDisposable> interface must provide its own protected virtual void Dispose(bool) method. Dispose() should call Dipose(true), and the finalizer should call Dispose(false). If you create an unsealed type that declares and implements the <xref:System.IDisposable> interface, you must define Dispose(bool) and call it. For more information, see [Clean up unmanaged resources (.NET guide)](/dotnet/standard/garbage-collection/unmanaged)and [Dispose pattern](/dotnet/standard/design-guidelines/dispose-pattern).
50
52
51
53
## Rule description
52
54
53
-
All IDisposable types should implement the Dispose pattern correctly.
55
+
All <xref:System.IDisposable> types should implement the [Dispose pattern](/dotnet/standard/design-guidelines/dispose-pattern) correctly.
54
56
55
57
## How to fix violations
56
58
57
-
Examine your code and determine which of the following resolutions will fix this violation.
59
+
Examine your code and determine which of the following resolutions will fix this violation:
58
60
59
-
- Remove IDisposable from the list of interfaces that are implemented by {0} and override the base class Dispose implementation instead.
61
+
- Remove <xref:System.IDisposable> from the list of interfaces that are implemented by your type, and override the base class Dispose implementation instead.
60
62
61
-
- Remove the finalizer from type {0}, override Dispose(bool disposing), and put the finalization logic in the code path where 'disposing' is false.
63
+
- Remove the finalizer from your type, override Dispose(bool disposing), and put the finalization logic in the code path where 'disposing' is false.
62
64
63
-
-Remove {0}, override Dispose(bool disposing), and put the dispose logic in the code path where 'disposing' is true.
65
+
-Override Dispose(bool disposing), and put the dispose logic in the code path where 'disposing' is true.
64
66
65
-
-Ensure that {0} is declared as public and sealed.
67
+
-Make sure that Dispose() is declared as public and [sealed](/dotnet/csharp/language-reference/keywords/sealed).
66
68
67
-
- Rename {0} to 'Dispose' and make sure that it is declared as public and sealed.
69
+
- Rename your dispose method to **Dispose** and make sure that it's declared as public and [sealed](/dotnet/csharp/language-reference/keywords/sealed).
68
70
69
-
- Make sure that {0} is declared as protected, virtual, and unsealed.
71
+
- Make sure that Dispose(bool) is declared as protected, virtual, and unsealed.
70
72
71
-
- Modify {0} so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance ('this' or 'Me' in [!INCLUDE[vbprvb](../code-quality/includes/vbprvb_md.md)]), and then returns.
73
+
- Modify Dispose() so that it calls Dispose(true), then calls <xref:System.GC.SuppressFinalize%2A> on the current object instance (`this`, or `Me` in Visual Basic), and then returns.
72
74
73
-
- Modify {0} so that it calls Dispose(false) and then returns.
75
+
- Modify your finalizer so that it calls Dispose(false) and then returns.
74
76
75
-
- If you are creating an unsealed type that declares and implements the IDisposable interface, make sure that the implementation of IDisposable follows the pattern that is described earlier in this section.
77
+
- If you create an unsealed type that declares and implements the <xref:System.IDisposable> interface, make sure that the implementation of <xref:System.IDisposable> follows the pattern that is described earlier in this section.
76
78
77
79
## When to suppress warnings
78
80
@@ -96,7 +98,7 @@ public class Resource : IDisposable
96
98
}
97
99
98
100
// NOTE: Leave out the finalizer altogether if this class doesn't
99
-
// own unmanaged resources itself, but leave the other methods
101
+
// own unmanaged resources, but leave the other methods
100
102
// exactly as they are.
101
103
~Resource()
102
104
{
@@ -124,4 +126,9 @@ public class Resource : IDisposable
0 commit comments