SA1200 Suppression Needed

Jul 13, 2012 at 12:37 AM

Please help?  In the Logger class, the "Common.Logging" assembly from NuGet is referenced.  This code fails:

namespace Company.Common.Utility
{
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Reflection;
    using System.Text;
    using Common.Logging;

    /// <summary>
    /// Ability to use a generic logger.
    /// </summary>
    public class Logger
    {

    }

}

because:

The type or namespace name 'Logging' does not exist in the namespace 'Company.Common' (are you missing an assembly reference?)

To build, the below was done, but now the SA1200 rule is not able to be suppressed in this unique exception case because the using statement must be first in the file...help?

using Common.Logging;

#if CODE_ANALYSIS
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "If placed inside, get: \"The type or namespace name 'Logging' does not exist in the namespace 'Company.Common' (are you missing an assembly reference?)\"")]
#endif
namespace Company.Common.Utility
{
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Reflection;
    using System.Text;

    /// <summary>
    /// Ability to use a generic logger.
    /// </summary>
    public class Logger
    {
    }
}

Jul 13, 2012 at 12:48 AM

Found the answer...putting this in the "Settings.Stylecop" file...

<SourceFileList>
    <SourceFile>Logger.cs</SourceFile>
    <Settings>
      <Analyzers>
        <Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
          <Rules>
            <Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
          </Rules>
        </Analyzer>
      </Analyzers>
    </Settings>
  </SourceFileList>
</StyleCopSettings>

Jul 16, 2012 at 9:22 AM

or you could use the global:: alias and then you can keep your using rule enabled