Running FxCop on some old stuff code gives me next error: “Implement IDisposable Correctly”.

And provided me with link to MSDN: http://msdn2.microsoft.com/ms244737(VS.90).aspx

I took look at existing code and it looked like:

        #region IDisposable Members
        void IDisposable.Dispose()
        {
            ShutdownServices();
        }
        #endregion

And here are lot of incorrect implementation of the IDisposable.
At first I added GC.SuppressFinalize(this); like here:

        void IDisposable.Dispose()
        {
            ShutdownServices();
            GC.SuppressFinalize(this);
        }

Of course it was not enough – it is needed to call Dispose(true) because my class is not sealed.
You also need to have re-overridden Finalize.

So code which passed FxCop verification looks like:

        #region IDisposable Members
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        ~ServiceLoader()
        {
            Dispose(false);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                ShutdownServices();
            }
        }
        #endregion

Please go to MSDN page and read it, since to know how to implement IDisposable correctly is important thing.

If you haven't subsribed yet, you can subsribe below: