Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 3.0
Tools
Development Tools
FxCop
FxCop Warnings
 Avoid uncalled private code
Collapse All/Expand All Collapse All
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
Avoid uncalled private code

TypeName

AvoidUncalledPrivateCode

CheckId

CA1811

Category

Microsoft.Performance

Breaking Change

NonBreaking

A private or internal (assembly-level) member does not have callers in the assembly, is not invoked by the common language runtime, and the member is not invoked by a delegate. The following members are not checked by this rule:

This rule can report false positives if there are entry points that are not currently identified by the rule logic. Also, it is possible that a compiler can emit non-callable code into an assembly.

To fix a violation of this rule, remove the non-callable code, or add code that calls it.

It is safe 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
Does not fire on internal members if InternalsVisibleToAttribute is present      David M. Kean - MSFT ... Clayton Rogers - MSFT   |   Edit   |   Show History

Currently if you have the InternalsVisibleToAttribute applied to the assembly being analyzed, this rule will not fire on any members marked as internal (Friend in Visual Basic, public private in C++) as it cannot be sure that a member is not being used by another friend assembly.

While it is not possible to work around this limitation in Visual Studio Code Analysis, the external standalone FxCop will fire on internal members if every friend assembly is present in the analysis.

Tags What's this?: fxcop (x) Add a tag
Flag as ContentBug
Build type preprocessor directives      David M. Kean - MSFT ... mikecvelide   |   Edit   |   Show History

This rule fires if there is calling code in a region that is in a preprocessor #if region such as the following case where, in a debug build, NotifyByEMail is thought not to be called.  Probably no way to fix it but definitely pay attention to it before you remove code regions detected by this rule since your code will compile fine and FXCop will tell you all is well until you flip the switch into release mode.

 

public void NotifyByEMail(string to) {

     ...

}

 

public void AnotherMethod() {

     ExecuteSomeCode();

#if !DEBUG

     NotifyByEMail(this.that@someplace.com);

#endif

}

Tags What's this?: Add a tag
Flag as ContentBug
Missing public key work in class definition      John Whitton   |   Edit   |   Show History
I also had this rule fire when I had forgotten to put the public key word infront of the class definition
class DimAngle : IEquatable<DimAngle>
{
etc.....
public string ToString(string formatType, double scalar, int decimalPlaces) Rule was fired on this function "line 556"
{
.....
}
}
should have been
class public DimAngle : IEquatable<DimAngle>
{ .....
}
However the order in which the rule was reported fired wasnt listed top to botton but was picked up at some method quite a way down the class structure. Upon further invesigation I found the rule had fired on other public Methods and also private constants fileds that were used in several places in the code. I wasted much time untill I realised my mistake. So a note to others check that you have made the class public if you recieve this type of message when not expected.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker