FxCop throwing error

Hi all,

I just ran an compilation of FxCop rules.

It's giving 2 error message:

  • CA0001: Rule=Design Rules#CA5035, Target=Welcome.Page_Load(System.Object,System.EventArgs):System.Void: Object reference not set to an instance of an object.
  • FxCopCmd.exe returned error code 2.

The above rule CA5035 when run independently doesn't throw this error but when I ran it with a combination of some 10 rules. It's giving the above error messages.

Can anyone tell me what to do with this

Please note that the 1st error message is not being thrown when I run the rule CA5035 independently and I've rectified the conditions too. There is no cases of object no being set to an instance( I guess).

Kindly advice somebody.

Thanks & regards,

ThunderRock




Answer this question

FxCop throwing error

  • Roach

    Have you attached to FxCop using the debugger to see which line is throwing the error

  • Jon Braganza

    No, there isn't enough information here to troubleshoot your problem. Can you please locate the XML output file FxCop generates when you see the problem, and try to locate the exact line of code that is raising the exception There should be a complete stack in the log.

    The name of the file will be [YourBinaryName].CodeAnalysisLog.xml.

    btw - what kind of project are you analyzing when the exception occurs can you analyze other project types successfully



  • andrewds17

    Hi David,

    Thanks for the concern. It's working now.

    I was running the FxCop on web applications. Now it's working fine.

    Thanks,

    ThunderRock


  • rternier

    I'll assume this is a custom rule as we do not have rules with a CheckID of CA5035.

    Without seeing the code, it's impossible to guess at what is causing the problem. Try debugging the issue by compiling your custom rules against FxCop 1.35, and attaching to FxCop during analysis (or rather just before it begins).



  • BipinP

    Hi David,

    This is a custom rule. I've included the code herewith. Kindly check and reply back. It's giving the same error as before.

    The code for rule CA5035 is as follows:

    public override ProblemCollection Check(Member pobjMember)

    {

    //Do the null check

    if (pobjMember == null)

    return null;

    // Declare a flag variable to check for Publish method found or not

    bool blnPublishFound = false;

    // Declare a flag variable to check for catch block found or not

    bool blnCatchFound = false;

    // Converts type 'Microsoft.Cci.Member' to 'Microsoft.Cci.Method'

    // via a built in conversion

    Method objMethod = pobjMember as Method;

    //If the method is null, return null

    if (objMethod == null)

    return null;

    //Store the method name in the string variable

    string strMethodName = objMethod.Name.Name;

    // Set a intCount

    int intCount = 0;

    //Check if the method is null. If not, then enter the condition

    if (RuleUtilities.IsEventHandling(objMethod))

    {

    //For loop is used to check through all the instruction inside the method

    for (int intCounter = intCount; intCounter < objMethod.Instructions.Length; intCounter++)

    {

    //If the opcode encountered is throw or rethrow, then passed.

    if ((objMethod.Instructions[intCounter].OpCode == OpCode._Catch) || intCount > 0)

    {

    // Set the catch flag to true as catch block is found

    blnCatchFound = true;

    // Check if the opcode value is call or callvirt. If yes, then condition passed

    if (objMethod.Instructions[intCounter].OpCode == OpCode.Call

    || objMethod.Instructions[intCounter].OpCode == OpCode.Callvirt)

    {

    // Store the full name of the instruction in a local variable

    string strTempStore = ((Microsoft.Cci.Method)(objMethod.Instructions[intCounter].Value)).FullName;

    // Check if the call or callvirt has operand Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(System.Exception)

    if (strTempStore.Contains("ExceptionManager.Publish"))

    {

    // Set the Publish method found flag to true.

    blnPublishFound = true;

    }

    // Else increment intCount

    else

    {

    intCount++;

    }

    }

    // If the call or callvirt is not found, then increment intCount

    // Go to next statement

    else

    {

    intCount++;

    }

    // Check for the opcode value _EndHandler. This indicates the end of the catch block

    // If found, then break

    if (objMethod.Instructions[intCounter].OpCode == OpCode._EndHandler)

    {

    // Check if Publish method is found. If not found, then add to problem collection

    if (blnCatchFound && !blnPublishFound)

    {

    // Add to problem collection

    Problems.Add(new Problem(GetResolution(strMethodName), strMethodName));

    break;

    }

    // Set the flags to false again so as to start the check for other catch block

    blnCatchFound = false;

    blnPublishFound = false;

    }

    }

    }

    }

    return Problems;

    }

    I've given only the check method part. The class inherits a base class which inherits from the

    BaseIntrospectionRule.

    Regards,

    ThunderRock


  • John R. Garrett

    Hi David,

    I've done that too. But when I used debugger, the rule is working fine. The above rule starts giving the errors only when all the rules which I have developed, run together. Otherwise each rule when run alone works fine....

    Can you tell me what could be the reason for this type of behaviour

    Thanks,

    ThunderRock


  • FxCop throwing error