New FxCop 1.312

The busy folks on the FxCop team have posted a new release, 1.312.  There’s 43 new rules and some of those rules look outstanding.  A couple of my favorites are the “Avoid unnecessary string creation” (which looks to see if you are creating extranious strings on the heap) and “Do not raise reserved exception types” (which ensures you don’t throw something like System.Exception directly).  The Read Me file discusses all the new stuff.

The team changed the custom rule SDK yet again, but the changes are for the better.  See the Read Me for all the changes.  Since many people are using the rules I developed for FxCop as part of my June 2004 and September 2004 Bugslayer columns, I updated all the rules I did to support FxCop 1.312, which you can download here.  Porting the rules to the new SDK interface wasn’t too bad.  In the near future, I’ll post an article here at the site which describes what’s necessary to do the porting.  If you have your own rules to port, take a look at the Empty Rule example in my code to see what’s different.

For rule writers, one major feature has been added to FxCop 1.312: when loading a rule that has a broken XML description, it finally tells you exactly which part of the XML is wrong!  In previous versions it was a complete trial and error process to find the error in your XML description.  Now FxCop tells you in the output window exactly what piece was wrong and why.  It’s a huge timesaver.  Thanks to the team for adding that.

If you have any ideas for rules, we’d love to hear about them!  Shoot me an email (john at this web site) or post in the comments.  The rules are fun to develop and if there are some good suggestions, I’ll write them.

John Robbins

View Comments

  • I feel the Fxcop rules are fine however there appears to be one naming convention that seems to be contradictory in Fxcop and Microsoft documentations. They say underscores are not allowed for camel cased class variables and at the same time you cant have properties named the same but differing in case, example of this is as follows:
    private string name;
    public string Name{
    get{
    return this.name
    }
    set{
    this.name=value
    }
    }
    if I were to underscore private string name (e.g _name) as above I will be breaking the rules also. Your thoughts on this will be appreciated

  • The Microsoft guidelines do not mention anywhere about not allowing underscores in private member variables, they only talk about public members.

  • I have some trouble with the rules Exception XML Document tag is missing. FxCop give me the error in this example. Anyone have a solution ?
    /// <exception cref="System.StackOverflowException">
    /// Lancé lorsqu'il y a des symboles invalides dans le format.
    /// </exception>
    private string Test ()
    {
    string test = "";
    try
    {
    if(test.Length > 0)
    {
    test= "HAHAHA";
    }
    }
    catch (System.StackOverflowException exc)
    {
    if (exc.Message.Equals ("TOTO"))
    {
    throw new System.StackOverflowException (exc.Message);
    }
    }
    return test;
    }

  • Hi! I have some questions:
    1. How to check local variable type of a function?
    2. How to check Namespace name?
    Please help me....

Recent Posts

8-Step AWS to Microsoft Azure Migration Strategy

Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…

3 weeks ago

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

4 weeks ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

1 month ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

2 months ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

2 months ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago