Earlier today I ran into CA1063 when running code analysis on some code at work.
I have two questions:
Why does the following code not cause CA1063 even though it clearly violates some of the demands (for example Dispose is overridden)
What is the actual problem with the code that caused the complicated scheme for having a virtual Dispose(bool) that is called by a sealed Dispose() and the Finalizer and so on....
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Foobar : IDisposable { public Foobar() { Console.Out.WriteLine("Constructor of Foobar"); } public virtual void Dispose() { Console.Out.WriteLine("Dispose of Foobar"); GC.SuppressFinalize(this); } ~Foobar() { Console.Out.WriteLine("Finalizer of Foobar"); } } class Derived : Foobar { public Derived() { Console.Out.WriteLine("Constructor of Derived"); } public override void Dispose() { Console.Out.WriteLine("Dispose of Derived"); GC.SuppressFinalize(this); base.Dispose(); } ~Derived() { Console.Out.WriteLine("Finalizer of Derived"); } } class Program { static void Main() { Console.Out.WriteLine("Start"); using (var foo = new Derived()) { Console.Out.WriteLine("..."); } Console.Out.WriteLine("End"); } } }