Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 3.0
Tools
Development Tools
FxCop
FxCop Warnings
Naming Warnings
 Type names should not match namespa...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual Studio Team System
Type names should not match namespaces

TypeName

TypeNamesShouldNotMatchNamespaces

CheckId

CA1724

Category

Microsoft.Naming

Breaking Change

Breaking

A type name matches one of the following namespace names in a case-insensitive comparison:

  • Collections

  • Forms

  • System

  • UI

Type names should not match the names of namespaces defined in the .NET Framework class library. Violating this rule can reduce the usability of the library.

Select a type name that does not match the name of a .NET Framework class library namespace.

For new development, there are no known scenarios where you must exclude a warning from this rule. For shipping libraries, you might have to exclude a warning from this rule.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Other matches      CommonGenius.com   |   Edit   |   Show History

The four names above are not the only ones that this rule complains about. This violation was raised over my use of "Security" as an object name, saying that it conflicted "in part" with "System.Web.Security". I work in the financial trading industry where a "security" is something that can be traded, and it is something that I have to represent in my object model. There is no synonym that will be widely recognized by others who are using my code; and we don't use the Web namespace at all, so the chance for confusion is minimal. I love FxCop, but once again Microsoft shows its astounding arrogance: "For new development, there are no known scenarios where you must exclude a warning from this rule." Sorry guys, but you can't possibly predict all possible scenarios, and you should stop assuming that you can.

1) The type names under "Cause" should either list all names which the rule might complain about, or it should be changed to say "A type name matches a namespace name from the .NET Framework class library, such as..."

2) Under "When to Exclude Warnings," instead of the first sentence, it should say something like: "Duplicating namespace and object names could cause confusion and reduce the usability of your code. Before excluding a warning from this rule, carefully consider whether there is an alternate name you could use that would be less confusing."

Other matches (cont.)      Markus Egger   |   Edit   |   Show History

It in fact seems that this rule is triggered whenever a class/type name is the same as the namespace it is contained in. For instance, I encountered this rule creating a type called "Documents" in a Xxx.Yyy.Documents namespace, and from a business point of view, naming the class "Documents" makes perfect sense (especially since this is a WCF service contract, where I want to make sure that the contract names make as much sense to the consumers as possible).

I would argue that the rule can be excluded in this case.

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker