We recommend using Visual Studio 2017

Basic Design Guideline Rules rule set for managed code


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Basic Design Guideline Rules rule set for managed code.

You can use the Microsoft Basic Design Guideline Rules rule set to focus on making your code easier to understand and use. You should include this rule set if your project includes library code or if you want to enforce best practices for code that is easy to maintain.

The Basic Design Guideline Rules include all the rules in the Microsoft Minimum Recommeded Rules rule set. For a list of the minimum rules, see Managed Recommended Rules rule set for managed code.

The following table describes all of the rules in the Microsoft Basic Design Guideline Rules rule set.

CA1001Types that own disposable fields should be disposable
CA1009Declare event handlers correctly
CA1016Mark assemblies with AssemblyVersionAttribute
CA1033Interface methods should be callable by child types
CA1049Types that own native resources should be disposable
CA1060Move P/Invokes to NativeMethods class
CA1061Do not hide base class methods
CA1063Implement IDisposable correctly
CA1065Do not raise exceptions in unexpected locations
CA1301Avoid duplicate accelerators
CA1400P/Invoke entry points should exist
CA1401P/Invokes should not be visible
CA1403Auto layout types should not be COM visible
CA1404Call GetLastError immediately after P/Invoke
CA1405COM visible type base types should be COM visible
CA1410COM registration methods should be matched
CA1415Declare P/Invokes correctly
CA1821Remove empty finalizers
CA1900Value type fields should be portable
CA1901P/Invoke declarations should be portable
CA2002Do not lock on objects with weak identity
CA2100Review SQL queries for security vulnerabilities
CA2101Specify marshaling for P/Invoke string arguments
CA2108Review declarative security on value types
CA2111Pointers should not be visible
CA2112Secured types should not expose fields
CA2114Method security should be a superset of type
CA2116APTCA methods should only call APTCA methods
CA2117APTCA types should only extend APTCA base types
CA2122Do not indirectly expose methods with link demands
CA2123Override link demands should be identical to base
CA2124Wrap vulnerable finally clauses in outer try
CA2126Type link demands require inheritance demands
CA2131Security critical types may not participate in type equivalence
CA2132Default constructors must be at least as critical as base type default constructors
CA2133Delegates must bind to methods with consistent transparency
CA2134Methods must keep consistent transparency when overriding base methods
CA2137Transparent methods must contain only verifiable IL
CA2138Transparent methods must not call methods with the SuppressUnmanagedCodeSecurity attribute
CA2140Transparent code must not reference security critical items
CA2141Transparent methods must not satisfy LinkDemands
CA2146Types must be at least as critical as their base types and interfaces
CA2147Transparent methods may not use security asserts
CA2149Transparent methods must not call into native code
CA2200Rethrow to preserve stack details
CA2202Do not dispose objects multiple times
CA2207Initialize value type static fields inline
CA2212Do not mark serviced components with WebMethod
CA2213Disposable fields should be disposed
CA2214Do not call overridable methods in constructors
CA2216Disposable types should declare finalizer
CA2220Finalizers should call base class finalizer
CA2229Implement serialization constructors
CA2231Overload operator equals on overriding ValueType.Equals
CA2232Mark Windows Forms entry points with STAThread
CA2235Mark all non-serializable fields
CA2236Call base class methods on ISerializable types
CA2237Mark ISerializable types with SerializableAttribute
CA2238Implement serialization methods correctly
CA2240Implement ISerializable correctly
CA2241Provide correct arguments to formatting methods
CA2242Test for NaN correctly
CA1000Do not declare static members on generic types
CA1002Do not expose generic lists
CA1003Use generic event handler instances
CA1004Generic methods should provide type parameter
CA1005Avoid excessive parameters on generic types
CA1006Do not nest generic types in member signatures
CA1007Use generics where appropriate
CA1008Enums should have zero value
CA1010Collections should implement generic interface
CA1011Consider passing base types as parameters
CA1012Abstract types should not have constructors
CA1013Overload operator equals on overloading add and subtract
CA1014Mark assemblies with CLSCompliantAttribute
CA1017Mark assemblies with ComVisibleAttribute
CA1018Mark attributes with AttributeUsageAttribute
CA1019Define accessors for attribute arguments
CA1023Indexers should not be multidimensional
CA1024Use properties where appropriate
CA1025Replace repetitive arguments with params array
CA1026Default parameters should not be used
CA1027Mark enums with FlagsAttribute
CA1028Enum storage should be Int32
CA1030Use events where appropriate
CA1031Do not catch general exception types
CA1032Implement standard exception constructors
CA1034Nested types should not be visible
CA1035ICollection implementations have strongly typed members
CA1036Override methods on comparable types
CA1038Enumerators should be strongly typed
CA1039Lists are strongly typed
CA1041Provide ObsoleteAttribute message
CA1043Use integral or string argument for indexers
CA1044Properties should not be write only
CA1046Do not overload operator equals on reference types
CA1047Do not declare protected members in sealed types
CA1048Do not declare virtual members in sealed types
CA1050Declare types in namespaces
CA1051Do not declare visible instance fields
CA1052Static holder types should be sealed
CA1053Static holder types should not have constructors
CA1054URI parameters should not be strings
CA1055URI return values should not be strings
CA1056URI properties should not be strings
CA1057String URI overloads call System.Uri overloads
CA1058Types should not extend certain base types
CA1059Members should not expose certain concrete types
CA1064Exceptions should be public
CA1500Variable names should not match field names
CA1502Avoid excessive complexity
CA1708Identifiers should differ by more than case
CA1716Identifiers should not match keywords
CA1801Review unused parameters
CA1804Remove unused locals
CA1809Avoid excessive locals
CA1810Initialize reference type static fields inline
CA1811Avoid uncalled private code
CA1812Avoid uninstantiated internal classes
CA1813Avoid unsealed attributes
CA1814Prefer jagged arrays over multidimensional
CA1815Override equals and operator equals on value types
CA1819Properties should not return arrays
CA1820Test for empty strings using string length
CA1822Mark members as static
CA1823Avoid unused private fields
CA2201Do not raise reserved exception types
CA2205Use managed equivalents of Win32 API
CA2208Instantiate argument exceptions correctly
CA2211Non-constant fields should not be visible
CA2217Do not mark enums with FlagsAttribute
CA2219Do not raise exceptions in exception clauses
CA2221Finalizers should be protected
CA2222Do not decrease inherited member visibility
CA2223Members should differ by more than return type
CA2224Override equals on overloading operator equals
CA2225Operator overloads have named alternates
CA2226Operators should have symmetrical overloads
CA2227Collection properties should be read only
CA2230Use params for variable arguments
CA2234Pass System.Uri objects instead of strings
CA2239Provide deserialization methods for optional fields