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:
- Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
- 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.
- On the View menu, click
Code.
- 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:
- In the Form1.cs file, locate the following code:
Application.Run(new Form1());
}
}
- 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;
}
} - 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:
- In the Form1.vb file, locate the following code:
- 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.
- In the Form1.vb file, locate the following code:
Class MyBrush
Inherits System.Drawing.Brush
- To resolve the error that you received in step b, paste
the following code after the code that you located in the previous step: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.
- In the Form1.vb file, locate the following code:
- 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:
- 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:
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
| 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