Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Item | Value |
---|---|
TypeName | TypesShouldNotExtendCertainBaseTypes |
CheckId | CA1058 |
Category | Microsoft.Design |
Breaking Change | Breaking |
An externally visible type extends certain base types. Currently, this rule reports types that derive from the following types:
For .NET Framework version 1, it was recommended to derive new exceptions from ApplicationException. The recommendation has changed and new exceptions should derive from System.Exception or one of its subclasses in the System namespace.
Do not create a subclass of XmlDocument if you want to create an XML view of an underlying object model or data source.
Use and/or extend generic collections whenever possible. Do not extend non-generic collections in your code, unless you shipped it previously.
Examples of Incorrect Usage
public class MyCollection : CollectionBase
{
}
public class MyReadOnlyCollection : ReadOnlyCollectionBase
{
}
Examples of Correct Usage
public class MyCollection : Collection<T>
{
}
public class MyReadOnlyCollection : ReadOnlyCollection<T>
{
}
To fix a violation of this rule, derive the type from a different base type or a generic collection.
Do not suppress a warning from this rule for violations about ApplicationException. It is safe to suppress a warning from this rule for violations about XmlDocument. It is safe to suppress a warning about a non-generic collection if the code was released previously.