How to implement dispose pattern with close method correctly (CA1063) <p>The Framework Design Guidelines (2nd Ed., page 327) say:</p> <blockquote> <p>CONSIDER providing method <code>Close()</code>, in addition to the <code>Dispose()</code>, if close is standard terminology in the area.</p> <p>When doing so, it is important that you make the Close implementation identical to <code>Dispose</code> and consider implementing <code>IDisposable.Dispose</code> method explicitly.</p> </blockquote> <p>So, following the provided example, I've got this class:</p> <pre><code>public class SomeClass : IDisposable { private SomeDisposable someInnerDisposable; public void Open() { this.someInnerDisposable = new SomeDisposable(); } void IDisposable.Dispose() { this.Close(); } public void Close() { this.Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { this.someInnerDisposable.Dispose(); this.someInnerDisposable = null; } } } </code></pre> <p>FxCop doesn't seem to like that:</p> <blockquote> <p>CA1816 : Microsoft.Usage : 'SomeClass.Close()' calls 'GC.SuppressFinalize(object)', a method that is typically only called within an implementation of 'IDisposable.Dispose'. Refer to the IDisposable pattern for more information.</p> <p>CA1816 : Microsoft.Usage : Change 'SomeClass.IDisposable.Dispose()' to call 'GC.SuppressFinalize(object)'. This will prevent unnecessary finalization of the object once it has been disposed and it has fallen out of scope.</p> <p>CA1063 : Microsoft.Design : Modify 'SomeClass.IDisposable.Dispose()' so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance ('this' or 'Me' in Visual Basic), and then returns.</p> <p>CA1063 : Microsoft.Design : Rename 'SomeClass.IDisposable.Dispose()' to 'Dispose' and ensure that it is declared as public and sealed.</p> </blockquote> <ul> <li>How do I implement the dispose pattern with close method correctly?</li> </ul> <p>-or-</p> <ul> <li>How do I suppress the warnings?</li> </ul> <p>I tried</p> <pre><code>[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification = "Framework Design Guidelines say it's ok.")] void IDisposable.Dispose() { this.Close(); } </code></pre> <p>but FxCop 1.36 still reports them.</p> <p><strong>EDIT</strong>: Changing it around as suggested eliminates all but this warning:</p> <blockquote> <p>CA1063 : Microsoft.Design : Rename 'SomeClass.IDisposable.Dispose()' to 'Dispose' and ensure that it is declared as public and sealed.</p> </blockquote> <p><strong>EDIT 2</strong>: CODE_ANALYSIS was indeed missing. Thanks.</p>