Questions tagged [fxcop-customrules]
18 questions
8
votes
1 answer
How do I debug Code Analysis custom rules?
I wrote some custom rules in C#, following the step-by-step instructions I've found on this site. When I try to run Code Analysis in visual-studio-2013, I get a CA0054 error in the CA result pane.
I would like to debug my rule, as the exception…

Crono
- 10,211
- 6
- 43
- 75
5
votes
1 answer
FxCop: custom rule for checking assembly info values
Is there a reasonably simple way to get FxCop to check that all my assemblies declare a particular attribute value? I want to make sure everyone has changed the default you get on creating a project:
[assembly: AssemblyCompany("Microsoft")] //…

Julia Hayward
- 1,987
- 1
- 14
- 16
5
votes
1 answer
Custom Rule in FxCop to only apply to methods called by particular type's method
I want to create an FxRule that applies a method, only if the method gets called from a specific class.
NOTE: I don't want to just apply a rule to a method of a particular class, i want to be able to handle methods calling other methods calling…

George Duckett
- 31,770
- 9
- 95
- 162
3
votes
2 answers
How to set up dependency rules?
I want to set up some new dependency rules for a repo which has multiple solutions and assemblies. Rule should be, such as:- in any project, all the assemblies of type .ABC. should not depend upon .XYZ.. Any violation of such rule should be caught…

S. V. Prasad
- 29
- 3
3
votes
0 answers
FxCopSdk RuleUtilities.GetDataFilePaths
I've been trying to use the following, but I cannot get either line to return any results:
var searchResults = RuleUtilities.GetDataFilePaths("BizTalkCopExclusions.txt", SearchFolders.Project);
var searchResults =…

charlie.mott
- 321
- 2
- 8
3
votes
2 answers
Detecting class with SerializationAttribute in a FxCop custom rule
I'm trying to write a FxCop rule that matches classes that are adorned with the Serializable attribute, but it seems like the attribute is being ignored.
Eg. given this sample class
[Serializable]
[Description]
public class…

David Gardiner
- 16,892
- 20
- 80
- 117
2
votes
1 answer
How to create FxCop Problem() object with correct line number in source
I have created an FxCop rule that checks for DateTime.Now use. It works pretty well, except that it reports the offending line number as the start of the method, rather than the line of code that actually calls DateTime.Now. What do I need to do…

slolife
- 19,520
- 20
- 78
- 121
2
votes
1 answer
Suppressing FXCOP error for vb.net Method
I want to suppress FXCOP error(CA1811) for specific vb.net function.
Like in c#, do we alternative of this in VB.net?
I am new to vb.net.

Karthik Karnam
- 170
- 11
2
votes
1 answer
Is there a standard FxCop rule that detects throwing new exceptions without setting InnerException?
Our (pretty large) code base has a few of these constructs:
try {
DoSomething();
}
catch (Exception e) {
CleanUp();
throw new MoreSpecificException();
}
And I want to ensure that we throw a new exception with InnerException set in most…

codeape
- 97,830
- 24
- 159
- 188
2
votes
1 answer
FxCop custom rule to check namespace
I am trying to write a custom rule in FxCop to validate if my namespace starts with a particular word. I have tried something like below:
public override ProblemCollection Check(string namespaceName, TypeNodeCollection types)
{
if…

Saket Kumar
- 4,363
- 4
- 32
- 55
2
votes
2 answers
fxcop custom rules - Inspecting source code to look for new keyword
I would like to avoid instanciating certain class with new, and force to use the factory class.
But I don't understand how to do that.
Can someone show me a little sample ?
Thanks in advance for any help,
Best regards

Tim
- 2,887
- 10
- 33
- 33
1
vote
1 answer
FXCop Custom Rule to detect if catch has logging (Custom Code Analysis)
I have implemented several "stock" Microsoft Code Analysis rules. However they were lacking in one area that they didn't have detection in a catch to see if logging was implemented.
So my test project has these two methods. I would expect to see one…

GPGVM
- 5,515
- 10
- 56
- 97
1
vote
1 answer
Custom Fxcop Rules with SonarQube
I want to use only custom rules on my code with SonarQube. I have just dll's of custom rules.
How Can I do that? As per document I understood that I need to create a new rule but not sure how to create it.

Ram
- 11,404
- 15
- 62
- 93
0
votes
1 answer
File names and line numbers missing from FXCOP output in SDK-style project targeting .NET Framework
We used FXCOP code analysis ("legacy") a lot in our solution. We are turning on many Microsoft rules, and also have written a large set of our own FXCOP-style analyzers for aspects of code that we wanted to have checked. And it all worked quite well…

ZbynekZ
- 1,532
- 10
- 16
0
votes
1 answer
Compare FxCop TypeNode to System.Type
I have an attribute named SearchableAttribute, which tags properties of classes. However, only properties of type string are allowed to be tagged with this [Searchable] attribute. In order to restict it, I am trying to write a CodeAnalysis rule…

Otto Abnormalverbraucher
- 699
- 1
- 9
- 26