Search code examples
c#fxcopexit-codeerror-codefxcopcmd

513 Error Code (exit code) FxCop using C#


I have VS2010, Windows 7 bits, FxCop 10.0

I execute Fxcopcmd.exe using Process.Start, and I get 513 "exitcode" (error code) value.

Todd King in below reference says:

In this case an exit code of 513 means FxCop had an Analysis Error (0x01) and an assembly references error (0x200)

http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/1191af28-d262-4e4f-95d9-73b682c2044c/

I think if it is like

    [Flags]
    public enum FxCopErrorCodes
    {
        NoErrors = 0x0,
        AnalysisError = 0x1,  // -fatalerror
        RuleExceptions = 0x2,
        ProjectLoadError = 0x4,
        AssemblyLoadError = 0x8,
        RuleLibraryLoadError = 0x10,
        ImportReportLoadError = 0x20,
        OutputError = 0x40,
        CommandlineSwitchError = 0x80,
        InitializationError = 0x100,
        AssemblyReferencesError = 0x200,
        BuildBreakingMessage = 0x400,
        UnknownError = 0x1000000,
    }

513 integer value is 0x201 (view int to hex string and Enum.Parse fails to cast string )

How can I know errors (Analysis Error (0x01) and an assembly references error (0x200)) programmatically using only exitcode (513 , 0x201) value ?

More about Error Codes for FxCopCmd and Code Analysis:


Solution

  • You can test for a specific value of your enum using a AND bitwise operation:

    FxCopErrorCodes code = (FxCopErrorCodes)0x201;
    if ((code & FxCopErrorCodes.InitializationError) == FxCopErrorCodes.InitializationError)
    {
        Console.WriteLine("InitializationError");
    }
    

    You could get the whole list of values using something like:

    private static IEnumerable<FxCopErrorCodes> GetMatchingValues(FxCopErrorCodes enumValue)
    {
        // Special case for 0, as it always match using the bitwise AND operation
        if (enumValue == 0)
        {
            yield return FxCopErrorCodes.NoErrors;
        }
    
        // Gets list of possible values for the enum
        var values = Enum.GetValues(typeof(FxCopErrorCodes)).Cast<FxCopErrorCodes>();
    
        // Iterates over values and return those that match
        foreach (var value in values)
        {
            if (value > 0 && (enumValue & value) == value)
            {
                yield return value;
            }
        }
    }