Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:44:23+00:00 2026-06-09T02:44:23+00:00

I am dealing with following case. I have a base class that have the

  • 0

I am dealing with following case. I have a base class that have the IDisposable pattern, it means that it have the public virtual Dispose() method and the protected virtual Dispose(bool) method. But I am not able to implement this patter in the derived class in such way that I will not receive any CA warnings. Please consider following example:

public class UtilizeClass : IDisposable
{
    private MyData data;

    public UtilizeClass()
    {
        data = new MyData();
    }

    public void Dispose()
    {
        data.Dispose(); // Cannot use Dispose(bool) because it is protected.
    }
}

public class MyData : Base, IDisposable
{
    // Here we have some managed resources that must be disposed.

    // How to implement the pattern?
}

public class Base : IDisposable
{
    public virtual void Dispose() { }
    protected virtual void Dispose(bool disposing) { }
}

All the time I receive contradictory CA warnings in the MyData class. For example: delete the Dispose() and move it logics to Dispose(bool).

Thank you very much for answer and help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:44:25+00:00Added an answer on June 9, 2026 at 2:44 am

    Your base class shouldn’t have void Dispose() be virtual, it should be implemented and invoke the virtual void Dispose(bool disposing) as part of its implementation.

    For more detail, and an alternate API that’s slightly clearer, check out:

    http://haacked.com/archive/2005/11/18/acloserlookatdisposepattern.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm dealing with a large code base that uses the following construct throughout class
Say I have a class, something like the following; class MyClass { public: MyClass();
I have following problem: I have class public class HockeyActivity extends SimpleBaseGameActivity implements IOnSceneTouchListener,
I am dealing with a commerical Java API that exposes only the following logging
I have the following code: class Program { static void Main(string[] args) { Test
...I have a Grails domain class dealing with geo location data for interacting with
I have the following monad transformer for dealing with errors in Haskell. instance (Monad
I have a list view class that just like NSCollectionView requires an additional prototype
I am dealing with some auto-generated XSLT code. It contains the following: string(string(.)) number(string(.))
I encountered a problem dealing with UTF-8, XML and Perl. The following is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.