Microsoft Knowledge Base Email Alertz

KBAlertz.com: (833898) - If you try to inherit from a class that contains only private constructors, you receive many error messages. This problem may occur in many different scenarios.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 833898 - Last Review: December 3, 2007 - Revision: 2.6

You receive error messages when you try to inherit from a class that contains only private constructors in Visual Studio .NET or in Visual Studio 2005

On This Page

SYMPTOMS

If you try to inherit from a class that contains only private constructors, you receive many error messages. This problem may occur in many different scenarios.

CAUSE

You receive these error messages because you cannot inherit from a class than contains only private constructors.

RESOLUTION

To resolve this problem, do not try to inherit from a class that contains only private constructors. For more information, see the "References" section of this article.

MORE INFORMATION

Steps to reproduce the behavior

To notice the types of error messages that you may receive if you try to inherit from a class that contains only private constructors, follow these steps:
  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. Use Microsoft Visual C# .NET or Microsoft Visual C# 2005, or Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 to create a Microsoft Windows application project that is named AccessLevelTest. By default, the Form1 form is created.
  3. On the View menu, click Code.
  4. Follow these steps, depending on whether you are using Visual C# .NET or Visual C# 2005, or Visual Basic .NET or Visual Basic 2005:
    • If you are using Visual C# .NET or Visual C# 2005, follow these steps:
      1. In the Form1.cs file, locate the following code:
              Application.Run(new Form1());
           }
        }
      2. Paste the following code after the code that you located in the previous step:
        public class MyClass : System.Drawing.Brush
        {
           public override object Clone()
           {
              return null;
           }
        }
      3. On the Build menu, click Build AccessLevelTest. You receive the following error message in the Task List window:
        'System.Drawing.Brush.Brush()' is inaccessible due to its protection level
    • If you are using Visual Basic .NET or Visual Basic 2005, follow these steps:
      1. In the Form1.vb file, locate the following code:
        End Class
      2. Paste the following code after the code that you located in the previous step:
        Class MyBrush
           Inherits System.Drawing.Brush
        
           Public Overloads Overrides Function Clone() As Object
           End Function
        
        End Class
        You receive the following error message in the Task List window:
        Class 'MyBrush' must declare a 'Sub New' because its base class 'Brush' does not have an accessible 'Sub New' that can be called with no arguments.
      3. In the Form1.vb file, locate the following code:
        Class MyBrush
           Inherits System.Drawing.Brush
      4. To resolve the error that you received in step b, paste the following code after the code that you located in the previous step:
        Sub New()
        End Sub
        You receive the following error message in the Task List window:
        First statement of this 'Sub New' must be a call to 'MyBase.New' or 'MyClass.New' because base class 'System.Drawing.Brush' of 'AccessLevelTest.Form1.MyBrush' does not have an accessible 'Sub New' that can be called with no arguments.
      5. In the Form1.vb file, locate the following code:
        Sub New()
      6. To resolve the error message that you received in step d, paste the following code after the code that you located in the previous step:
        MyBase.New()
        • If you are using Visual Basic .NET 2003, you receive the following error message in the Task List window:
          'System.Drawing.Brush.Private Sub New()' is not accessible in this context because it is 'Private'.
        • If you are using Visual Basic .NET 2002, you receive the following error message in the Task List window:
          'System.Drawing.Brush.Private Overloads Sub New()' is not accessible in this context because it is 'Private'.
        Additionally, Dynamic Help for this error message suggests that, to correct this error, you must remove the Private access modifier from the method definition in the base class. However, you cannot modify the base class (System.Drawing.Brush) because it is part of the Microsoft .NET Framework.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
Inheritance
http://msdn2.microsoft.com/en-us/library/5x4yd9d5(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/5x4yd9d5(vs.71).aspx)

Access Modifiers
http://msdn2.microsoft.com/en-us/library/wxh6fsc7(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/wxh6fsc7(vs.71).aspx)

4.6 Accessibility
http://msdn2.microsoft.com/en-us/library/aa711877(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/aa711877(VS.71).aspx)

APPLIES TO
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Academic Edition
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 2.0
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Standard Edition
Keywords: 
kbvs2005swept kbvs2005applies kbprb kbsample kberrmsg kbcode KB833898
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please