diff --git a/GuidelinesForNewRules.md b/GuidelinesForNewRules.md index b9cc846c28..19d7cce8ff 100644 --- a/GuidelinesForNewRules.md +++ b/GuidelinesForNewRules.md @@ -1,5 +1,6 @@ -Guidelines for contributing a new Code Analysis (CA) rule to the repo -================================================================= +# Contribution Guidelines + +## Guidelines for contributing a new Code Analysis (CA) rule to the repo 1. File an issue describing your proposed rule prior to working on a PR. This will ensure that the rule gets triaged and there is no duplicate work involved from an existing rule OR another contributor working on a similar rule. 1. For .NET API related analyzer suggestions, please open an issue at [dotnet/runtime/issues](https://github.com/dotnet/runtime/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) with [code-analyzer](https://github.com/dotnet/runtime/issues?q=is%3Aopen+is%3Aissue+label%3Acode-analyzer+sort%3Aupdated-desc) label. @@ -24,25 +25,25 @@ 3. A good rule of thumb is that if your analyzer needs to invoke `GetTypeByMetadataName`, then most likely it is an API specific analyzer and belongs to `Microsoft.NetCore.Analyzers`. 5. Documentation requirements: - 1. **New CA rule must be documented**: Each rule ID `CAxxxx` is automatically assigned the help link https://docs.microsoft.com/visualstudio/code-quality/caxxxx. The documentation for this page is populated from `caxxxx.md` file at https://github.com/MicrosoftDocs/visualstudio-docs/tree/master/docs/code-quality. For example, `CA1000` is documented at [ca1000.md](https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/code-quality/ca1000.md) file. Documenting a new rule is primarily ensuring a PR is sent to `MicrosoftDocs` repo to add `caxxxx.md` file for the new rule. Detailed steps are given below. + 1. **New CA rule must be documented**: Each rule ID `CAxxxx` is automatically assigned the help link `https://docs.microsoft.com/visualstudio/code-quality/caxxxx`. The documentation for this page is populated from `caxxxx.md` file at [visualstudio-docs code-quality folder](https://github.com/MicrosoftDocs/visualstudio-docs/tree/master/docs/code-quality). For example, `CA1000` is documented at [ca1000.md](https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/code-quality/ca1000.md) file. Documenting a new rule is primarily ensuring a PR is sent to `MicrosoftDocs` repo to add `caxxxx.md` file for the new rule. Detailed steps are given below. 2. **Documentation PR must be submitted within ONE WEEK of the rule implementation being merged**. Note that we will communicate this requirement on each PR contributing a new CA rule. We reserve the right to revert the rule implementation PR if this documentation requirement is not met. - - Steps for creating documentation PR: - - 1. Documentation PR must be submitted to the following repo: - 1. _External contributors_: https://github.com/MicrosoftDocs/visualstudio-docs - 2. _Internal contributors_: https://github.com/MicrosoftDocs/visualstudio-docs-pr - - Please review [CONTRIBUTING.md](https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/CONTRIBUTING.md) for guidelines. - 2. Documentation PR for a new CA rule must have following changes: - 1. New `caxxxx.md` file under `/docs/code-quality` sub-folder with rule documentation. - - `TIP:` Clone an existing `caxxxx.md` file inside `/docs/code-quality` sub-folder in the repo, rename it and update the contents for the new rule. - 2. Update the following tables in the repo for supported CA rule IDs: - 1. Add entry in `/docs/code-quality/toc.yml` under appropriate category. - 2. Add entry in `/docs/code-quality/code-analysis-warnings-for-managed-code-by-checkid.md` - 3. Add entry in the documentation file `/docs/code-quality/<%category%>-warnings.md` for rule's `Category`. For example: - 1. For a new rule with category `Design`, add an entry to `/docs/code-quality/design-warnings.md`. - 2. For a new rule with category `Performance`, add an entry to `/docs/code-quality/performance-warnings.md`, and so on. - - If for some exceptional reason you are unable to submit a PR, please [file a documentation issue](https://github.com/MicrosoftDocs/visualstudio-docs/issues) to add documentation for the rule in future. Please include all relevant information in the issue to allow the documentation experts to easily author the documentation. For example, see [this issue](https://github.com/MicrosoftDocs/visualstudio-docs/issues/3454). + +## Guidelines for creating documentation PR + +1. Documentation PR must be submitted to the following repo: + 1. [_External contributors_](https://github.com/MicrosoftDocs/visualstudio-docs) + 2. [_Internal contributors_](https://github.com/MicrosoftDocs/visualstudio-docs-pr) + + Please review [CONTRIBUTING.md](https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/CONTRIBUTING.md) for guidelines. +2. Documentation PR for a new CA rule must have following changes: + 1. New `caxxxx.md` file under `/docs/code-quality` sub-folder with rule documentation. + + `TIP:` Clone an existing `caxxxx.md` file inside `/docs/code-quality` sub-folder in the repo, rename it and update the contents for the new rule. + 2. Update the following tables in the repo for supported CA rule IDs: + 1. Add entry in `/docs/code-quality/toc.yml` under appropriate category. + 2. Add entry in `/docs/code-quality/code-analysis-warnings-for-managed-code-by-checkid.md` + 3. Add entry in the documentation file `/docs/code-quality/<%category%>-warnings.md` for rule's `Category`. For example: + 1. For a new rule with category `Design`, add an entry to `/docs/code-quality/design-warnings.md`. + 2. For a new rule with category `Performance`, add an entry to `/docs/code-quality/performance-warnings.md`, and so on. + +If for some exceptional reason you are unable to submit a PR, please [file a documentation issue](https://github.com/MicrosoftDocs/visualstudio-docs/issues) to add documentation for the rule in future. Please include all relevant information in the issue to allow the documentation experts to easily author the documentation. For example, see [this issue](https://github.com/MicrosoftDocs/visualstudio-docs/issues/3454). diff --git a/PostReleaseActivities.md b/PostReleaseActivities.md index f83f9c1f7d..313b87d1dd 100644 --- a/PostReleaseActivities.md +++ b/PostReleaseActivities.md @@ -1,5 +1,6 @@ -Post-release activities -================================================================= +# Post-release activities + +## Steps to generate Packages Please follow the below steps after publishing analyzer NuGet packages from this repo onto NuGet.org: @@ -20,8 +21,7 @@ Please follow the below steps after publishing analyzer NuGet packages from this 7. Move all the entries from `AnalyzerReleases.Unshipped.md` to `AnalyzerReleases.Shipped.md` for various analyzer NuGet package projects under a new "Release" section in the shipped file. 8. Create and submit a PR with the above changes. -Steps to generate Release Notes -================================================================= +## Steps to generate Release Notes 1. Checkout the sources for the release branch locally. This would normally be the master branch. 2. Build. diff --git a/README.md b/README.md index 79a2b9b225..ed492152eb 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,19 @@ |:--------:|:-----------:|:-------------:| |**master**| [![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/roslyn-analyzers/roslyn-analyzers-CI?branchName=master&jobName=Windows&configuration=Windows%20Debug&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=457&branchName=master) [![codecov](https://codecov.io/gh/dotnet/roslyn-analyzers/branch/master/graph/badge.svg)](https://codecov.io/gh/dotnet/roslyn-analyzers) | [![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/roslyn-analyzers/roslyn-analyzers-CI?branchName=master&jobName=Windows&configuration=Windows%20Release&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=457&branchName=master) | -# What is Roslyn? +## What is Roslyn? Roslyn is the compiler platform for .NET. It consists of the compiler itself and a powerful set of APIs to interact with the compiler. The Roslyn platform is hosted at [github.com/dotnet/roslyn](https://github.com/dotnet/roslyn). -# What are Roslyn Analyzers? +## What are Roslyn Analyzers? Roslyn analyzers analyze your code for style, quality and maintainability, design and other issues. The documentation for Roslyn Analyzers can be found at [docs.microsoft.com/visualstudio/code-quality/roslyn-analyzers-overview](https://docs.microsoft.com/visualstudio/code-quality/roslyn-analyzers-overview). Microsoft created a set of analyzers called [Microsoft.CodeAnalysis.FxCopAnalyzers](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers) that contains the most important "FxCop" rules from static code analysis, converted to Roslyn analyzers. These analyzers check your code for security, performance, and design issues, among others. The documentation for FxCop analyzers in Visual Studio can be found at [docs.microsoft.com/visualstudio/code-quality/install-fxcop-analyzers](https://docs.microsoft.com/visualstudio/code-quality/install-fxcop-analyzers). -# Microsoft.CodeAnalysis.NetAnalyzers +## Main analyzers + +### Microsoft.CodeAnalysis.NetAnalyzers *Latest stable version:* _Not yet released_ @@ -40,7 +42,7 @@ You do not need to manually install this NuGet package to your project if you ar ``` -# Microsoft.CodeAnalysis.FxCopAnalyzers +### Microsoft.CodeAnalysis.FxCopAnalyzers *Latest stable version:* [![NuGet](https://img.shields.io/nuget/v/Microsoft.CodeAnalysis.FxCopAnalyzers.svg)](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers) @@ -52,9 +54,9 @@ The documentation for all the ported and unported FxCop rules can be found at [d This analyzer package contains all the ported FxCop rules that are applicable for both _.NetCore/.NetStandard_ and _Desktop .NetFramework_ projects. You **do not need to install any separate analyzer package from this repo to get target-framework specific FxCop rules**. [More info about rules in this package](src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.md) -## The following are subpackages or NuGet dependencies that are automatically installed when you install the Microsoft.CodeAnalysis.FxCopAnalyzers package: +#### The following are subpackages or NuGet dependencies that are automatically installed when you install the Microsoft.CodeAnalysis.FxCopAnalyzers package: -### Microsoft.CodeQuality.Analyzers +#### Microsoft.CodeQuality.Analyzers *Latest stable version:* [![NuGet](https://img.shields.io/nuget/v/Microsoft.CodeQuality.Analyzers.svg)](https://www.nuget.org/packages/Microsoft.CodeQuality.Analyzers) @@ -62,7 +64,7 @@ This analyzer package contains all the ported FxCop rules that are applicable fo This package contains common code quality improvement rules that are not specific to usage of any particular API. For example, [CA1801](https://docs.microsoft.com/visualstudio/code-quality/ca1801-review-unused-parameters) (ReviewUnusedParameters) flags parameters that are unused and is part of this package. [More info about rules in this package](src/Microsoft.CodeQuality.Analyzers/Microsoft.CodeQuality.Analyzers.md) -### Microsoft.NetCore.Analyzers +#### Microsoft.NetCore.Analyzers *Latest stable version:* [![NuGet](https://img.shields.io/nuget/v/Microsoft.NetCore.Analyzers.svg)](https://www.nuget.org/packages/Microsoft.NetCore.Analyzers) @@ -72,7 +74,7 @@ This package contains rules for correct usage of APIs that are present in _.NetC **NOTE:** This analyzer package is applicable for both _.NetCore/.NetStandard_ and _Desktop .NetFramework_ projects. If the API whose usage is being checked exists only in _.NetCore/.NetStandard_ libraries, then the analyzer will bail out silently for _Desktop .NetFramework_ projects. Otherwise, if the API exists in both _.NetCore/.NetStandard_ and _Desktop .NetFramework_ libraries, the analyzer will run correctly for both _.NetCore/.NetStandard_ and _Desktop .NetFramework_ projects. [More info about rules in this package](src/Microsoft.NetCore.Analyzers/Microsoft.NetCore.Analyzers.md) -### Microsoft.NetFramework.Analyzers +#### Microsoft.NetFramework.Analyzers *Latest stable version:* [![NuGet](https://img.shields.io/nuget/v/Microsoft.NetFramework.Analyzers.svg)](https://www.nuget.org/packages/Microsoft.NetFramework.Analyzers) @@ -82,7 +84,7 @@ This package contains rules for correct usage of APIs that are present only in _ **NOTE:** The analyzers in this package will silently bail out if installed on a _.NetCore/.NetStandard_ project that do not have the underlying API whose usage is being checked. If future versions of _.NetCore/.NetStandard_ libraries include these APIs, the analyzers will automatically light up on _.NetCore/.NetStandard_ projects that target these libraries. [More info about rules in this package](src/Microsoft.NetFramework.Analyzers/Microsoft.NetFramework.Analyzers.md) -# Other Analyzer Packages +## Other Analyzer Packages ### Microsoft.CodeAnalysis.Analyzers @@ -126,7 +128,7 @@ The MetaCompilation Analyzer is an analyzer that functions as a tutorial to teac For instructions on using this tutorial, see [Instructions](https://github.com/dotnet/roslyn-analyzers/blob/master/src/MetaCompilation.Analyzers/Core/ReadMe.md#instructions). -# Getting Started +## Getting Started 1. Install Visual Studio 2019 or later, with at least the following workloads: 1. .NET desktop development @@ -138,19 +140,19 @@ For instructions on using this tutorial, see [Instructions](https://github.com/d 5. Run the restore and build command: `build.cmd`(in the command prompt) or `.\build.cmd`(in PowerShell). 6. Execute tests: `test.cmd`(in the command prompt) or `.\test.cmd`(in PowerShell). -# Submitting Pull Requests +## Submitting Pull Requests Prior to submitting a pull request, ensure the build and all tests pass using using steps 4 and 5 above. -# Guidelines for contributing a new Code Analysis (CA) rule to the repo +## Guidelines for contributing a new Code Analysis (CA) rule to the repo See [GuidelinesForNewRules.md](.//GuidelinesForNewRules.md) for contributing a new Code Analysis rule to the repo. -# Versioning Scheme for Analyzer Packages +## Versioning Scheme for Analyzer Packages See [VERSIONING.md](.//VERSIONING.md) for the versioning scheme for all analyzer packages built out of this repo. -# Recommended version of Analyzer Packages +## Recommended version of Analyzer Packages Recommended Visual Studio Version: **Visual Studio 2019 16.3 RTW or later** diff --git a/SECURITY.md b/SECURITY.md index 27ff07f700..1dd871f56f 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,10 +6,11 @@ The .NET Core and ASP.NET Core support policy, including supported versions can ## Reporting a Vulnerability -Security issues and bugs should be reported privately to the Microsoft Security Response Center (MSRC), either by emailing secure@microsoft.com or via the portal at https://msrc.microsoft.com. -You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your +Security issues and bugs should be reported privately to the Microsoft Security Response Center (MSRC), either by emailing secure@microsoft.com or via the portal at +[https://msrc.microsoft.com](https://msrc.microsoft.com). +You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the [MSRC Report an Issue FAQ](https://www.microsoft.com/en-us/msrc/faqs-report-an-issue). Reports via MSRC may qualify for the .NET Core Bug Bounty. Details of the .NET Core Bug Bounty including terms and conditions are at [https://aka.ms/corebounty](https://aka.ms/corebounty). -Please do not open issues for anything you think might have a security implication. \ No newline at end of file +Please do not open issues for anything you think might have a security implication. diff --git a/VERSIONING.md b/VERSIONING.md index b6a0343f9d..25002e16a1 100644 --- a/VERSIONING.md +++ b/VERSIONING.md @@ -1,5 +1,4 @@ -Versioning scheme for .NET Compiler Platform ("Roslyn") Analyzers -================================================================= +# Versioning scheme for .NET Compiler Platform ("Roslyn") Analyzers Following is the versioning scheme that is being used for analyzer packages: @@ -9,8 +8,7 @@ Following is the versioning scheme that is being used for analyzer packages: **NOTE**: An exception was applied to the above versioning scheme when we moved the analyzer packages to version 1.1.0, while still depending on version 1.0.0 of Microsoft.CodeAnalysis. This was done as we had mistakenly published 1.1.0-beta1 pre-release packages for some analyzer packages on nuget.org. -Current and Released Versions of Analyzer Packages -================================================== +## Current and Released Versions of Analyzer Packages Current version of all analyzer packages that are built out of this repo are tracked by the `VersionPrefix` property defined in [Versions.Props](.//eng//Versions.props) diff --git a/docs/Analyzer Configuration.md b/docs/Analyzer Configuration.md index ac73b29dcd..7aae10ab7f 100644 --- a/docs/Analyzer Configuration.md +++ b/docs/Analyzer Configuration.md @@ -263,7 +263,7 @@ Option Name: `excluded_symbol_names` Configurable Rules: [CA1303](https://docs.microsoft.com/visualstudio/code-quality/ca1303), [CA1062](https://docs.microsoft.com/visualstudio/code-quality/ca1062), -[CA1304](https://docs.microsoft.com/visualstudio/code-quality/ca1304), +[CA1304](https://docs.microsoft.com/visualstudio/code-quality/ca1304), [CA1508](https://docs.microsoft.com/visualstudio/code-quality/ca1508), [CA2000](https://docs.microsoft.com/visualstudio/code-quality/ca2000), [CA2100](https://docs.microsoft.com/visualstudio/code-quality/ca2100), @@ -404,7 +404,7 @@ Configurable Rules: [CA1508](https://docs.microsoft.com/visualstudio/code-quality/ca1508), [CA2000](https://docs.microsoft.com/visualstudio/code-quality/ca2000), [CA2100](https://docs.microsoft.com/visualstudio/code-quality/ca2100), -[CA2213](https://docs.microsoft.com/visualstudio/code-quality/ca2213), +[CA2213](https://docs.microsoft.com/visualstudio/code-quality/ca2213), Taint analysis rules #### Interprocedural analysis Kind @@ -528,6 +528,7 @@ class Test ``` #### Points to analysis kind for DFA rules based on PointsToAnalysis + Option Name: `points_to_analysis_kind` Configurable Rules: All DFA rules @@ -696,6 +697,7 @@ Default Value: Namespace, NamedType, Method, Property, Event, Parameter Example: `dotnet_code_quality.CA1716.analyzed_symbol_kinds = Namespace, Property` ### Use naming heuristic + Option Name: `use_naming_heuristic` Configurable Rules: [CA1303](https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1303) @@ -707,14 +709,16 @@ Default Value: `false` Example: `dotnet_code_quality.CA1303.use_naming_heuristic = true` ### Additional use results methods + Option Name: `additional_use_results_methods` Configurable Rules: [CA1806](https://docs.microsoft.com/en-us/visualstudio/code-quality/CA1806) Option Values: Names of additional methods (separated by '|') for CA1806. Allowed method name formats: + 1. Method name only (includes all methods with the name, regardless of the containing type or namespace) - 2. Fully qualified names in the symbol's documentation ID format: https://github.com/dotnet/csharplang/blob/master/spec/documentation-comments.md#id-string-format + 2. Fully qualified names in the [symbol's documentation ID format](https://github.com/dotnet/csharplang/blob/master/spec/documentation-comments.md#id-string-format) with an optional "M:" prefix. Default Value: None @@ -729,6 +733,7 @@ Examples: |`dotnet_code_quality.CA1806.additional_use_results_methods = M:NS1.MyType1.MyMethod1(ParamType)\|M:NS2.MyType2.MyMethod2(ParamType)` | Matches specific methods 'MyMethod1' and 'MyMethod2' with respective fully qualified signature ### Allowed suffixes + Option Name: `allowed_suffixes` Configurable Rules: [CA1711](https://docs.microsoft.com/visualstudio/code-quality/ca1711) diff --git a/docs/Documenting your analyzers.md b/docs/Documenting your analyzers.md index f4afaea050..ae96449f9a 100644 --- a/docs/Documenting your analyzers.md +++ b/docs/Documenting your analyzers.md @@ -33,13 +33,13 @@ but you can use any source for the stable URI, including (for example) any facility your company might provide for registering URIs. 6. In your analyzers, set the value of the `HelpLinkUri` property of -your `DiagnosticDescriptor` to the (preferably stable) URI you provided. +your `DiagnosticDescriptor` to the (preferably stable) URI you provided. **Note** Some analyzers produce diagnostics with more than one rule id. For example, the [`EquatableAnalyzer`](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.ApiDesignGuidelines.Analyzers/Core/EquatableAnalyzer.cs) in [`Microsoft.ApiDesignGuidelines.Analyzers`](https://github.com/dotnet/roslyn-analyzers/tree/master/src/Microsoft.ApiDesignGuidelines.Analyzers) produces diagnostics with two rule ids: -`CA1066` ("Implement IEquatable when overriding Object.Equals") -and `CA1067` ("Override Object.Equals when implementing IEquatable"). +`CA1066` ("Implement IEquatable\ when overriding Object.Equals") +and `CA1067` ("Override Object.Equals when implementing IEquatable\"). In such a case, create a separate reference page for each rule id. In this case, we would have `CA1066_ImplementIEquatableOfTWhenOverridingObjectEquals.md` and `CA1067_OverrideObjectEqualsWhenImplementingIEquatableOfT.md`. diff --git a/docs/FxCopPort/Porting FxCop Rules to Roslyn.md b/docs/FxCopPort/Porting FxCop Rules to Roslyn.md index b942cd3559..cf5279c62d 100644 --- a/docs/FxCopPort/Porting FxCop Rules to Roslyn.md +++ b/docs/FxCopPort/Porting FxCop Rules to Roslyn.md @@ -11,8 +11,8 @@ However, we do not envision the new Roslyn-based managed analysis rules as a str * FxCop includes rules related to a variety of quality concerns (standardization of public API conventions, correct usage of core BCL classes, internationalization, performance, security, etc.). This suggests that we can profitably unbundle the FxCop rules into a collection of packages, each serving a clearly defined purpose, and allow developers to select the packages that meet their needs. * To many people, the name "FxCop" means _nothing_. VS's customers just see a mass of Code Analysis rules, and there's no mention of FxCop anywhere in VS. (The only place the name appears is in the name of the command line tool FxCopCmd.exe.) Customers care mostly about getting some guidance from static analysis. But they can't figure out which of the 300+ rules matter to them, because the rules are not arranged in useful groups (other than the category, which is rather generic). - -* Most of the rules in VS today were written about 10 years ago. Platforms and guidelines have evolved since then. Many of the rules either don't make sense or aren't that valuable any more. For example, the introduction of generics has rendered many of the rules obsolete, as has the deprecation of CAS (Code Access Security) Policy and Security-Transparent Code. Experience has shown that other rules provide limited value and/or are a source of noise (false positives). + +* Most of the rules in VS today were written about 10 years ago. Platforms and guidelines have evolved since then. Many of the rules either don't make sense or aren't that valuable any more. For example, the introduction of generics has rendered many of the rules obsolete, as has the deprecation of CAS (Code Access Security) Policy and Security-Transparent Code. Experience has shown that other rules provide limited value and/or are a source of noise (false positives). For these reasons, we stopped thinking about these rules as "FxCop analyzers". Instead, we looked at the inventory of all the rules that exist today, and factored them according to the APIs they relate to and the purposes they serve. As part of this exercise, we identified the rules that provided the highest value. We chose to implement only those rules as analyzers, and not to re-implement low-value rules. In addition, we are adding new rules to fill the gaps that have appeared in the last 10 years, for example, rules related to `async` or `ImmutableCollections`. @@ -22,9 +22,9 @@ In the remainder of this document, we explain the principles we used to decide h * In the spirit of [Code-Aware libraries](https://channel9.msdn.com/Events/Build/2015/3-725), if a rule is about the usage of a specific API, and the rule doesn't make sense if that API is not referenced, then that rule should ship with that API. For example, rules about `ImmutableArray` (which resides in System.Collections.Immutable.dll) should reside in an analyzer assembly System.Collections.Immutable.Analyzers.dll, which would be included in the System.Collections.Immutable NuGet package. -* Some types reside in different .NET assemblies, depending on which flavor of .NET you use. For example, in the .NET Framework, `IDisposable` resides in mscorlib.dll, whereas in [.NET Core](http://blogs.msdn.com/b/dotnet/archive/2014/11/12/net-core-is-open-source.aspx), it resides in System.Runtime.dll. Where should we place analyzers that examine uses of `IDisposable`: in mscorlib.Analyzers.dll or in System.Runtime.Analyzers.dll? We should choose the .NET Core version of the types; that is, we should place the `IDisposable` analyzers in System.Runtime.Analyzers.dll. +* Some types reside in different .NET assemblies, depending on which flavor of .NET you use. For example, in the .NET Framework, `IDisposable` resides in mscorlib.dll, whereas in [.NET Core](http://blogs.msdn.com/b/dotnet/archive/2014/11/12/net-core-is-open-source.aspx), it resides in System.Runtime.dll. Where should we place analyzers that examine uses of `IDisposable`: in mscorlib.Analyzers.dll or in System.Runtime.Analyzers.dll? We should choose the .NET Core version of the types; that is, we should place the `IDisposable` analyzers in System.Runtime.Analyzers.dll. - The rationale for this choice is that developers using .NET Core, which is delivered as a set of NuGet packages, will automatically get exactly the API-specific analyzers they need. Developers using .NET Framework will still need to manually download the API-specific analyzers. For those developers, we might consider creating a consolidated NuGet package containing the analyzers for all types in the .NET framework. By doing these two things, we minimize the number of times developers have to search for and download API-specific analyzer packages. + The rationale for this choice is that developers using .NET Core, which is delivered as a set of NuGet packages, will automatically get exactly the API-specific analyzers they need. Developers using .NET Framework will still need to manually download the API-specific analyzers. For those developers, we might consider creating a consolidated NuGet package containing the analyzers for all types in the .NET framework. By doing these two things, we minimize the number of times developers have to search for and download API-specific analyzer packages. * Rules that do not relate to the usage of specific APIs, but relate instead to more general coding guidelines, should be organized according to the intended purpose of those guidelines. For example, some rules might help API authors produce consistent public APIs, but those rules might not make sense for test assemblies. (We will package those analyzers in Microsoft.ApiDesignGuidelines.Analyzers.dll.) As another example, there might be some rules that restrict the expressiveness of the language (by discouraging the use of certain language features) in order to gain a performance advantage. Such rules would only apply in a specific context where that tradeoff is acceptable, and hence it would be useful to place them in a separate NuGet package. @@ -41,7 +41,7 @@ There are rules about types in the following contract assemblies: * **System.Runtime.InteropServices.Analyzers** - Contains analyzers related to interop and marshalling. This package already exists. * **System.Security.Cryptography.Algorithms.Analyzers** - Contains analyzers with guidelines for crypto algorithm usage. This is a new package. - + * **System.Xml.Analyzers** - Contains analyzers for types dealing with XML across the System.Xml.* contracts. This is a new package. * **Desktop.Analyzers** - Contains analyzers for APIs that are present in the desktop .NET Framework but not in the new .NET Core API set. Since the .NET framework isn't available in a piecemeal fashion, there's not much value in breaking this down further. @@ -55,7 +55,7 @@ There are rules about types in the following contract assemblies: * **Microsoft.Maintainability.Analyzers** - Contains rules that contains metrics-based and heuristics-based rules to assess complexity, maintainability, and readability. * **Microsoft.QualityGuidelines.Analyzers** - Contains miscellaneous rules related to code quality, which do not fall into any of the other packages. - + * **Text.Analyzers** - Contains rules that analyze code as text. The existing rules check spelling errors in programming elements such as resource string names and identifiers. Future rules could do things such as flagging comments for inappropriate or deprecated terms. * **Roslyn.Internal.Analyzers** - Contains rules about some internal types in the Roslyn code base, meant as guidelines for Roslyn contributors as opposed to Roslyn consumers. @@ -72,4 +72,4 @@ We have populated the "Port?" column of the spreadsheet with our decisions. (NOT ## Feedback -Although we are currently actively executing on this plan, please do provide feedback about the plan, the factoring, individual rules, rules that should be rewritten, rules that should be cut, and/or anything else. +Although we are currently actively executing on this plan, please do provide feedback about the plan, the factoring, individual rules, rules that should be rewritten, rules that should be cut, and/or anything else. diff --git a/docs/FxCopPort/Proposed FxCop rule changes in Roslyn.md b/docs/FxCopPort/Proposed FxCop rule changes in Roslyn.md index cae2105b89..2563f6f7d7 100644 --- a/docs/FxCopPort/Proposed FxCop rule changes in Roslyn.md +++ b/docs/FxCopPort/Proposed FxCop rule changes in Roslyn.md @@ -74,5 +74,5 @@ Why shouldn't all publicly visible methods follow this rule? We decided not to port this because of a high false positive rate, and our opinion that it was not of high value. We have had the following pushback on this decision: > @stilgarSCA: :-1: on this decision. Despite the fact that this causes a lot of false positives, I think it's worth keeping the rule for the correctly identified issues. End users always have the option of disabling rules for which they find no value. - +> > Several others have also argued for reversing this decision, as can be seen in the comments of [issue #695](https://github.com/dotnet/roslyn-analyzers/issues/695) and [issue #291](https://github.com/dotnet/roslyn-analyzers/issues/291). diff --git a/docs/NetCore_GettingStarted.md b/docs/NetCore_GettingStarted.md index acb0284f18..6a180ba2c6 100644 --- a/docs/NetCore_GettingStarted.md +++ b/docs/NetCore_GettingStarted.md @@ -1,72 +1,72 @@ # Getting started with .NetCore/.NetStandard Analyzers 1. Read through the [.NET Compiler Platform SDK](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/) for understanding the different Roslyn elements `(Syntax Nodes, Tokens, Trivia)`. The factory methods and APIs are super useful. -2. Learning this [tutorial](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix) for custom analyzer and trying it some level is very useful to get started. It is pretty easy step by step tutorial, it is time saving as it has a template generated for us (with analyzer, fixer and unit test), has good explanation, would give you pretty good understanding on how Roslyn analyzers work. -3. Clone the `dotnet/roslyn-analyzers` repo, install all required dependencies and build the repo by the [instructions](https://github.com/dotnet/roslyn-analyzers#getting-started). -4. Follow the coding style of the `dotnet/roslyn-analyzers` repo. [Guidelines about new rule id and doc](https://github.com/dotnet/roslyn-analyzers/blob/master/GuidelinesForNewRules.md). +2. Learning this [tutorial](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix) for custom analyzer and trying it some level is very useful to get started. It is pretty easy step by step tutorial, it is time saving as it has a template generated for us (with analyzer, fixer and unit test), has good explanation, would give you pretty good understanding on how Roslyn analyzers work. +3. Clone the `dotnet/roslyn-analyzers` repo, install all required dependencies and build the repo by the [instructions](https://github.com/dotnet/roslyn-analyzers#getting-started). +4. Follow the coding style of the `dotnet/roslyn-analyzers` repo. [Guidelines about new rule id and doc](https://github.com/dotnet/roslyn-analyzers/blob/master/GuidelinesForNewRules.md). 5. Open `RoslynAnalyzers.sln` and open the package where you are creating your analyzer. In our case, it is mostly `Microsoft.CodeAnalysis.NetAnalyzers`->`Microsoft.NetCore.Analyzers`. Create your analyzer and/or fixer class in the corresponding folder. -6. Add a message, title and description for your analyzer into `MicrosoftNetCoreAnalyzersResources.resx` and build the repo before using them, the language specific resources will be generated. -7. Make sure you have done everything from the [Definition of done list](#definition-of-done) below. +6. Add a message, title and description for your analyzer into `MicrosoftNetCoreAnalyzersResources.resx` and build the repo before using them, the language specific resources will be generated. +7. Make sure you have done everything from the [Definition of done list](#definition-of-done) below. -## Definition of done +## Definition of done -- Analyzer implemented to work for C# and VB. - - Unit tests for C#: - - All scenarios covered. - - Prefer markup syntax for the majority of tests. - - If your analyzer has placeholders in the diagnostic message and you want to test the arguments, write a smaller number of tests using the `VerifyCS.Diagnostic` syntax to construct specific diagnostic forms. +- Analyzer implemented to work for C# and VB. + - Unit tests for C#: + - All scenarios covered. + - Prefer markup syntax for the majority of tests. + - If your analyzer has placeholders in the diagnostic message and you want to test the arguments, write a smaller number of tests using the `VerifyCS.Diagnostic` syntax to construct specific diagnostic forms. - Unit tests for VB: - - Obvious positive and negative scenarios covered. - - If the implementation uses any syntax-specific code, then all scenarios must be covered. -- Fixer implemented for C#, using the language-agnostic APIs if possible. - - If the fixer can be entirely implemented with language-agnostic APIs `(IOperation)`, then VB support is essentially free. - - With a language-agnostic fixer, apply the attribute to indicate the fixer also applies to VB and add mainline VB tests. - - If language-specific APIs are needed to implement the fixer, the VB fixer is not required. - - Do not separate analyzer tests from code fix tests. If the analyzer has a code fix, then write all your tests as code fix tests. - - Calling `VerifyCodeFixAsync(source, source)` verifies that the analyzer either does not produce diagnostics, or produces diagnostics where no code fix is offered. - - Calling `VerifyCodeFixAsync(source, fixedSource)` verifies the diagnostics (analyzer testing) and verifies that the code fix on source produces the expected output. + - Obvious positive and negative scenarios covered. + - If the implementation uses any syntax-specific code, then all scenarios must be covered. +- Fixer implemented for C#, using the language-agnostic APIs if possible. + - If the fixer can be entirely implemented with language-agnostic APIs `(IOperation)`, then VB support is essentially free. + - With a language-agnostic fixer, apply the attribute to indicate the fixer also applies to VB and add mainline VB tests. + - If language-specific APIs are needed to implement the fixer, the VB fixer is not required. + - Do not separate analyzer tests from code fix tests. If the analyzer has a code fix, then write all your tests as code fix tests. + - Calling `VerifyCodeFixAsync(source, source)` verifies that the analyzer either does not produce diagnostics, or produces diagnostics where no code fix is offered. + - Calling `VerifyCodeFixAsync(source, fixedSource)` verifies the diagnostics (analyzer testing) and verifies that the code fix on source produces the expected output. - Run the analyzer locally against `dotnet/runtime` and `dotnet/roslyn-analyzers` [instructions](#Testing-against-the-Runtime-and-Roslyn-analyzers-repo). - - Review each of the failures in those repositories and determine the course of action for each. - - Use the failures to discover nuance and guide the implementation details. - - Run the analyzer against `dotnet/roslyn` [instruction](#Testing-against-the-Roslyn-repo), and if feasable with `dotnet/aspnetcore` repos. - - Document for review: matching and non-matching scenarios, including any discovered nuance. - - Failures in all `dotnet` repos are addressed. + - Review each of the failures in those repositories and determine the course of action for each. + - Use the failures to discover nuance and guide the implementation details. + - Run the analyzer against `dotnet/roslyn` [instruction](#Testing-against-the-Roslyn-repo), and if feasable with `dotnet/aspnetcore` repos. + - Document for review: matching and non-matching scenarios, including any discovered nuance. + - Failures in all `dotnet` repos are addressed. - Document for review: severity, default, categorization, numbering, titles, messages, and descriptions. -- Create the appropriate documentation for [docs.microsoft.com](https://github.com/MicrosoftDocs/visualstudio-docs-pr/tree/master/docs/code-quality) within **ONE WEEK**, instructions available on OneNote. External contributors should create an issue at https://github.com/microsoftDocs/visualstudio-docs/issues with a subject `Add documentation for analyzer rule [Your Rule ID]`. -- PR merged into `dotnet/roslyn-analyzers`. +- Create the appropriate documentation for [docs.microsoft.com](https://github.com/MicrosoftDocs/visualstudio-docs-pr/tree/master/docs/code-quality) within **ONE WEEK**, instructions available on OneNote. External contributors should create [an issue](https://github.com/microsoftDocs/visualstudio-docs/issues) with a subject `Add documentation for analyzer rule [Your Rule ID]`. +- PR merged into `dotnet/roslyn-analyzers`. -## Testing against the Runtime and Roslyn-analyzers repo +## Testing against the Runtime and Roslyn-analyzers repo -1. Navigate to the root of the Roslyn-analyzers repo and run these commands: - - `cd roslyn-analyzers` - - `set RUNTIMEPACKAGEVERSION=3.0.0` +1. Navigate to the root of the Roslyn-analyzers repo and run these commands: + - `cd roslyn-analyzers` + - `set RUNTIMEPACKAGEVERSION=3.0.0` - `build.cmd -ci /p:AssemblyVersion=%RUNTIMEPACKAGEVERSION% /p:AutoGenerateAssemblyVersion=false /p:OfficialBuild=true` - For testing against `dotnet/runtime`: - `cd artifacts\bin\Microsoft.CodeAnalysis.CSharp.NetAnalyzers\Debug\netstandard2.0` - For testing against `dotnet/roslyn-analyzers`: - - `cd artifacts\bin\Microsoft.NetCore.CSharp.Analyzers\Debug\netstandard2.0` + - `cd artifacts\bin\Microsoft.NetCore.CSharp.Analyzers\Debug\netstandard2.0` 2. Copy the two DLLs and replace the NuGet cache entries used by `dotnet/runtime` and `dotnet/roslyn-analyzers`. They might be in `"runtime/.packages/..."` or `"%USERPROFILE%/.nuget/packages/... "`. You can check the exact path by building something in runtime with /bl and checking the binlog file. - - Example for `dotnet/runtime`: + - Example for `dotnet/runtime`: - `copy /y *.dll %USERPROFILE%\.nuget\packages\Microsoft.CodeAnalysis.NetAnalyzers\%RUNTIMEPACKAGEVERSION%\analyzers\dotnet\cs` - - Example for `dotnet/roslyn-analyzers`: + - Example for `dotnet/roslyn-analyzers`: - `copy /y *.dll %USERPROFILE%\.nuget\packages\Microsoft.NetCore.Analyzers\%RUNTIMEPACKAGEVERSION%\analyzers\dotnet\cs` 3. Build the roslyn-analyzers with `build.cmd`, now new analyzers will be used from updated nuget packages and you would see the warnings if diagnostics found. -4. If failures found, review each of the failures and determine the course of action for each. +4. If failures found, review each of the failures and determine the course of action for each. - Improve analyzer to reduce false positives, fix valid warnings, in a very rare edge cases suppress them. -5. Make sure all failures addressed and corresponding PR(s) merged. -6. Switch to the runtime repo. -7. Build the runtime repo, either do a complete build or build each repo separately (coreclr, libraries, mono). -8. In case no any failure introduce an error somewhere to prove that the rule ran. +5. Make sure all failures addressed and corresponding PR(s) merged. +6. Switch to the runtime repo. +7. Build the runtime repo, either do a complete build or build each repo separately (coreclr, libraries, mono). +8. In case no any failure introduce an error somewhere to prove that the rule ran. - Be careful about in which project you are producing an error, choose an API not having reference from other APIs, else all dependent API's will fail. -9. If failures found, repeat step 4-5 to evaluate and address all warnings. +9. If failures found, repeat step 4-5 to evaluate and address all warnings. -## Testing against the Roslyn repo +## Testing against the Roslyn repo -1. Clone `dotnet/roslyn` and build it with this command: +1. Clone `dotnet/roslyn` and build it with this command: - `Build.cmd -restore -Configuration Release` 2. Build `dotnet/roslyn-analyzers` in debug mode: - `Build.cmd -Configuration Debug` -3. Run AnalyzerRunner from the Roslyn root directory to get the diagnostics. - - `.\artifacts\bin\AnalyzerRunner\Release\netcoreapp3.1\AnalyzerRunner.exe ..\roslyn-analyzers\artifacts\bin\Microsoft.NetCore.Analyzers.Package\Debug\netstandard2.0 .\Roslyn.sln /stats /concurrent /a AnalyzerNameToTest /log Output.txt` +3. Run AnalyzerRunner from the Roslyn root directory to get the diagnostics. + - `.\artifacts\bin\AnalyzerRunner\Release\netcoreapp3.1\AnalyzerRunner.exe ..\roslyn-analyzers\artifacts\bin\Microsoft.NetCore.Analyzers.Package\Debug\netstandard2.0 .\Roslyn.sln /stats /concurrent /a AnalyzerNameToTest /log Output.txt` - Do not forget change value after `/a` option with your testing analyzer name. -The diagnostics reported by the analyzer will be listed in Output.txt. +The diagnostics reported by the analyzer will be listed in Output.txt. diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md index 0d5e800254..bea48bfff7 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md +++ b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md @@ -2,148 +2,147 @@ ## RS1001: Missing diagnostic analyzer attribute +Non-abstract sub-types of DiagnosticAnalyzer should be marked with DiagnosticAnalyzerAttribute(s). The argument to this attribute(s), if any, determine the supported languages for the analyzer. Analyzer types without this attribute will be ignored by the analysis engine. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Non-abstract sub-types of DiagnosticAnalyzer should be marked with DiagnosticAnalyzerAttribute(s). The argument to this attribute(s), if any, determine the supported languages for the analyzer. Analyzer types without this attribute will be ignored by the analysis engine. +--- ## RS1002: Missing kind argument when registering an analyzer action +You must specify at least one syntax, symbol or operation kind when registering a syntax, symbol, or operation analyzer action respectively. Otherwise, the registered action will never be invoked during analysis. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -You must specify at least one syntax, symbol or operation kind when registering a syntax, symbol, or operation analyzer action respectively. Otherwise, the registered action will never be invoked during analysis. +--- ## RS1003: Unsupported SymbolKind argument when registering a symbol analyzer action +SymbolKind '{0}' is not supported for symbol analyzer actions + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -SymbolKind '{0}' is not supported for symbol analyzer actions +--- ## RS1004: Recommend adding language support to diagnostic analyzer +Diagnostic analyzer is marked as supporting only one language, but the analyzer assembly doesn't seem to refer to any language specific CodeAnalysis assemblies, and so is likely to work for more than one language. Consider adding an additional language argument to DiagnosticAnalyzerAttribute. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Diagnostic analyzer is marked as supporting only one language, but the analyzer assembly doesn't seem to refer to any language specific CodeAnalysis assemblies, and so is likely to work for more than one language. Consider adding an additional language argument to DiagnosticAnalyzerAttribute. +--- ## RS1005: ReportDiagnostic invoked with an unsupported DiagnosticDescriptor +ReportDiagnostic should only be invoked with supported DiagnosticDescriptors that are returned from DiagnosticAnalyzer.SupportedDiagnostics property. Otherwise, the reported diagnostic will be filtered out by the analysis engine. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -ReportDiagnostic should only be invoked with supported DiagnosticDescriptors that are returned from DiagnosticAnalyzer.SupportedDiagnostics property. Otherwise, the reported diagnostic will be filtered out by the analysis engine. +--- ## RS1006: Invalid type argument for DiagnosticAnalyzer's Register method +DiagnosticAnalyzer's language-specific Register methods, such as RegisterSyntaxNodeAction, RegisterCodeBlockStartAction and RegisterCodeBlockEndAction, expect a language-specific 'SyntaxKind' type argument for it's 'TLanguageKindEnumName' type parameter. Otherwise, the registered analyzer action can never be invoked during analysis. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -DiagnosticAnalyzer's language-specific Register methods, such as RegisterSyntaxNodeAction, RegisterCodeBlockStartAction and RegisterCodeBlockEndAction, expect a language-specific 'SyntaxKind' type argument for it's 'TLanguageKindEnumName' type parameter. Otherwise, the registered analyzer action can never be invoked during analysis. +--- ## RS1007: Provide localizable arguments to diagnostic descriptor constructor +If your diagnostic analyzer and it's reported diagnostics need to be localizable, then the supported DiagnosticDescriptors used for constructing the diagnostics must also be localizable. If so, then localizable argument(s) must be provided for parameter 'title' (and optionally 'description') to the diagnostic descriptor constructor to ensure that the descriptor is localizable. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisLocalization| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -If your diagnostic analyzer and it's reported diagnostics need to be localizable, then the supported DiagnosticDescriptors used for constructing the diagnostics must also be localizable. If so, then localizable argument(s) must be provided for parameter 'title' (and optionally 'description') to the diagnostic descriptor constructor to ensure that the descriptor is localizable. +--- ## RS1008: Avoid storing per-compilation data into the fields of a diagnostic analyzer +Instance of a diagnostic analyzer might outlive the lifetime of compilation. Hence, storing per-compilation data, such as symbols, into the fields of a diagnostic analyzer might cause stale compilations to stay alive and cause memory leaks. Instead, you should store this data on a separate type instantiated in a compilation start action, registered using 'AnalysisContext.RegisterCompilationStartAction' API. An instance of this type will be created per-compilation and it won't outlive compilation's lifetime, hence avoiding memory leaks. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisPerformance| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Instance of a diagnostic analyzer might outlive the lifetime of compilation. Hence, storing per-compilation data, such as symbols, into the fields of a diagnostic analyzer might cause stale compilations to stay alive and cause memory leaks. Instead, you should store this data on a separate type instantiated in a compilation start action, registered using 'AnalysisContext.RegisterCompilationStartAction' API. An instance of this type will be created per-compilation and it won't outlive compilation's lifetime, hence avoiding memory leaks. +--- ## RS1009: Only internal implementations of this interface are allowed +The author of this interface did not intend to have third party implementations of this interface and reserves the right to change it. Implementing this interface could therefore result in a source or binary compatibility issue with a future version of this interface. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCompatibility| |Enabled|True| |Severity|Error| |CodeFix|False| - -### Rule description - -The author of this interface did not intend to have third party implementations of this interface and reserves the right to change it. Implementing this interface could therefore result in a source or binary compatibility issue with a future version of this interface. +--- ## RS1010: Create code actions should have a unique EquivalenceKey for FixAll occurrences support +A CodeFixProvider that intends to support fix all occurrences must classify the registered code actions into equivalence classes by assigning it an explicit, non-null equivalence key which is unique for each kind of code action created by this fixer. This enables the FixAllProvider to fix all diagnostics in the required scope by applying code actions from this fixer that are in the equivalence class of the trigger code action. + |Item|Value| |-|-| |Category|Correctness| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1011: Use code actions that have a unique EquivalenceKey for FixAll occurrences support A CodeFixProvider that intends to support fix all occurrences must classify the registered code actions into equivalence classes by assigning it an explicit, non-null equivalence key which is unique for each kind of code action created by this fixer. This enables the FixAllProvider to fix all diagnostics in the required scope by applying code actions from this fixer that are in the equivalence class of the trigger code action. -## RS1011: Use code actions that have a unique EquivalenceKey for FixAll occurrences support - |Item|Value| |-|-| |Category|Correctness| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1012: Start action has no registered actions -A CodeFixProvider that intends to support fix all occurrences must classify the registered code actions into equivalence classes by assigning it an explicit, non-null equivalence key which is unique for each kind of code action created by this fixer. This enables the FixAllProvider to fix all diagnostics in the required scope by applying code actions from this fixer that are in the equivalence class of the trigger code action. +An analyzer start action enables performing stateful analysis over a given code unit, such as a code block, compilation, etc. Careful design is necessary to achieve efficient analyzer execution without memory leaks. Use the following guidelines for writing such analyzers: -## RS1012: Start action has no registered actions +1. Define a new scope for the registered start action, possibly with a private nested type for analyzing each code unit. + +2. If required, define and initialize state in the start action. + +3. Register at least one non-end action that refers to this state in the start action. If no such action is necessary, consider replacing the start action with a non-start action. For example, a CodeBlockStartAction with no registered actions or only a registered CodeBlockEndAction should be replaced with a CodeBlockAction. + +4. If required, register an end action to report diagnostics based on the final state. |Item|Value| |-|-| @@ -151,12 +150,19 @@ A CodeFixProvider that intends to support fix all occurrences must classify the |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1013: Start action has no registered non-end actions -An analyzer start action enables performing stateful analysis over a given code unit, such as a code block, compilation, etc. Careful design is necessary to achieve efficient analyzer execution without memory leaks. Use the following guidelines for writing such analyzers:
1. Define a new scope for the registered start action, possibly with a private nested type for analyzing each code unit.
2. If required, define and initialize state in the start action.
3. Register at least one non-end action that refers to this state in the start action. If no such action is necessary, consider replacing the start action with a non-start action. For example, a CodeBlockStartAction with no registered actions or only a registered CodeBlockEndAction should be replaced with a CodeBlockAction.
4. If required, register an end action to report diagnostics based on the final state. +An analyzer start action enables performing stateful analysis over a given code unit, such as a code block, compilation, etc. Careful design is necessary to achieve efficient analyzer execution without memory leaks. Use the following guidelines for writing such analyzers: -## RS1013: Start action has no registered non-end actions +1. Define a new scope for the registered start action, possibly with a private nested type for analyzing each code unit. + +2. If required, define and initialize state in the start action. + +3. Register at least one non-end action that refers to this state in the start action. If no such action is necessary, consider replacing the start action with a non-start action. For example, a CodeBlockStartAction with no registered actions or only a registered CodeBlockEndAction should be replaced with a CodeBlockAction. + +4. If required, register an end action to report diagnostics based on the final state. |Item|Value| |-|-| @@ -164,385 +170,352 @@ An analyzer start action enables performing stateful analysis over a given code |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -An analyzer start action enables performing stateful analysis over a given code unit, such as a code block, compilation, etc. Careful design is necessary to achieve efficient analyzer execution without memory leaks. Use the following guidelines for writing such analyzers:
1. Define a new scope for the registered start action, possibly with a private nested type for analyzing each code unit.
2. If required, define and initialize state in the start action.
3. Register at least one non-end action that refers to this state in the start action. If no such action is necessary, consider replacing the start action with a non-start action. For example, a CodeBlockStartAction with no registered actions or only a registered CodeBlockEndAction should be replaced with a CodeBlockAction.
4. If required, register an end action to report diagnostics based on the final state. +--- ## RS1014: Do not ignore values returned by methods on immutable objects. +Many objects exposed by Roslyn are immutable. The return value from a method invocation on these objects should not be ignored. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Many objects exposed by Roslyn are immutable. The return value from a method invocation on these objects should not be ignored. +--- ## RS1015: Provide non-null 'helpLinkUri' value to diagnostic descriptor constructor +The 'helpLinkUri' value is used to show information when this diagnostic in the error list. Every analyzer should have a helpLinkUri specified which points to a help page that does not change over time. + |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisDocumentation| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The 'helpLinkUri' value is used to show information when this diagnostic in the error list. Every analyzer should have a helpLinkUri specified which points to a help page that does not change over time. +--- ## RS1016: Code fix providers should provide FixAll support +A CodeFixProvider should provide FixAll support to enable users to fix multiple instances of the underlying diagnostic with a single code fix. See documenation at https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for further details. + |Item|Value| |-|-| |Category|Correctness| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -A CodeFixProvider should provide FixAll support to enable users to fix multiple instances of the underlying diagnostic with a single code fix. See documenation at https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for further details. +--- ## RS1017: DiagnosticId for analyzers must be a non-null constant -|Item|Value| -|-|-| -|Category|MicrosoftCodeAnalysisDesign| -|Enabled|True| -|Severity|Warning| -|CodeFix|False| - -### Rule description - DiagnosticId for analyzers must be a non-null constant. -## RS1018: DiagnosticId for analyzers must be in specified format - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1018: DiagnosticId for analyzers must be in specified format DiagnosticId for analyzers must be in specified format. -## RS1019: DiagnosticId must be unique across analyzers - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1019: DiagnosticId must be unique across analyzers DiagnosticId must be unique across analyzers. -## RS1020: Category for analyzers must be from the specified values - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisDesign| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1020: Category for analyzers must be from the specified values Category for analyzers must be from the specified values. -## RS1021: Invalid entry in analyzer category and diagnostic ID range specification file - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisDesign| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1021: Invalid entry in analyzer category and diagnostic ID range specification file Invalid entry in analyzer category and diagnostic ID range specification file. -## RS1022: Do not use types from Workspaces assembly in an analyzer - |Item|Value| |-|-| -|Category|MicrosoftCodeAnalysisCorrectness| +|Category|MicrosoftCodeAnalysisDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1022: Do not use types from Workspaces assembly in an analyzer Diagnostic analyzer types should not use types from Workspaces assemblies. Workspaces assemblies are only available when the analyzer executes in Visual Studio IDE live analysis, but are not available during command line build. Referencing types from Workspaces assemblies will lead to runtime exception during analyzer execution in command line build. -## [RS1023](https://go.microsoft.com/fwlink/?linkid=874285): Upgrade MSBuildWorkspace - |Item|Value| |-|-| -|Category|Library| +|Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS1023](https://go.microsoft.com/fwlink/?linkid=874285): Upgrade MSBuildWorkspace MSBuildWorkspace has moved to the Microsoft.CodeAnalysis.Workspaces.MSBuild NuGet package and there are breaking API changes. -## RS1024: Compare symbols correctly - |Item|Value| |-|-| -|Category|MicrosoftCodeAnalysisCorrectness| +|Category|Library| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## RS1024: Compare symbols correctly Symbols should be compared for equality, not identity. -## RS1025: Configure generated code analysis - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## RS1025: Configure generated code analysis Configure generated code analysis -## RS1026: Enable concurrent execution - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## RS1026: Enable concurrent execution Enable concurrent execution -## RS1027: Types marked with DiagnosticAnalyzerAttribute(s) should inherit from DiagnosticAnalyzer - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## RS1027: Types marked with DiagnosticAnalyzerAttribute(s) should inherit from DiagnosticAnalyzer Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) -## RS1028: Provide non-null 'customTags' value to diagnostic descriptor constructor - |Item|Value| |-|-| -|Category|MicrosoftCodeAnalysisDocumentation| -|Enabled|False| +|Category|MicrosoftCodeAnalysisCorrectness| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1028: Provide non-null 'customTags' value to diagnostic descriptor constructor The 'customTags' value is used as a way to enable specific actions and filters on diagnostic descriptors based on the specific values of the tags. Every Roslyn analyzer should have at least one tag from the 'WellKnownDiagnosticTags' class. -## RS1029: Do not use reserved diagnostic IDs - |Item|Value| |-|-| -|Category|MicrosoftCodeAnalysisDesign| -|Enabled|True| +|Category|MicrosoftCodeAnalysisDocumentation| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1029: Do not use reserved diagnostic IDs DiagnosticId for analyzers should not use reserved IDs. -## RS1030: Do not invoke Compilation.GetSemanticModel() method within a diagnostic analyzer - |Item|Value| |-|-| -|Category|MicrosoftCodeAnalysisCorrectness| +|Category|MicrosoftCodeAnalysisDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## RS1030: Do not invoke Compilation.GetSemanticModel() method within a diagnostic analyzer 'GetSemanticModel' is an expensive method to invoke within a diagnostic analyzer because it creates a completely new semantic model, which does not share compilation data with the compiler or other analyzers. This incurs an additional performance cost during semantic analysis. Instead, consider registering a different analyzer action which allows used of a shared 'SemanticModel', such as 'RegisterOperationAction', 'RegisterSyntaxNodeAction', or 'RegisterSemanticModelAction'. -## RS1031: Define diagnostic title correctly - |Item|Value| |-|-| -|Category|MicrosoftCodeAnalysisDesign| +|Category|MicrosoftCodeAnalysisCorrectness| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## RS1031: Define diagnostic title correctly The diagnostic title should not contain a period, nor any line return character, nor any leading or trailing whitespaces -## RS1032: Define diagnostic message correctly - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisDesign| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## RS1032: Define diagnostic message correctly The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period -## RS1033: Define diagnostic description correctly - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisDesign| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## RS1033: Define diagnostic description correctly The diagnostic description should be one or multiple sentences ending with a punctuation sign and should not have any leading or trailing whitespaces -## [RS2000](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Add analyzer diagnostic IDs to analyzer release. - |Item|Value| |-|-| -|Category|MicrosoftCodeAnalysisReleaseTracking| +|Category|MicrosoftCodeAnalysisDesign| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [RS2000](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Add analyzer diagnostic IDs to analyzer release. All supported analyzer diagnostic IDs should be part of an analyzer release. -## [RS2001](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Ensure up-to-date entry for analyzer diagnostic IDs are added to analyzer release. - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [RS2001](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Ensure up-to-date entry for analyzer diagnostic IDs are added to analyzer release. Ensure up-to-date entry for analyzer diagnostic IDs are added to analyzer release. -## [RS2002](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Do not add removed analyzer diagnostic IDs to unshipped analyzer release. - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [RS2002](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Do not add removed analyzer diagnostic IDs to unshipped analyzer release. Entries for analyzer diagnostic IDs that are no longer reported and never shipped can be removed from unshipped analyzer release. -## [RS2003](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Shipped diagnostic IDs that are no longer reported should have an entry in the 'Removed Rules' table in unshipped file. - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS2003](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Shipped diagnostic IDs that are no longer reported should have an entry in the 'Removed Rules' table in unshipped file. Shipped diagnostic IDs that are no longer reported should have an entry in the 'Removed Rules' table in unshipped file. -## [RS2004](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Diagnostic IDs marked as removed in analyzer release file should not be reported by analyzers. - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS2004](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Diagnostic IDs marked as removed in analyzer release file should not be reported by analyzers. Diagnostic IDs marked as removed in analyzer release file should not be reported by analyzers. -## [RS2005](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Remove duplicate entries for diagnostic ID in the same analyzer release. - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS2005](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Remove duplicate entries for diagnostic ID in the same analyzer release. Remove duplicate entries for diagnostic ID in the same analyzer release. -## [RS2006](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Remove duplicate entries for diagnostic ID between analyzer releases. - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS2006](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Remove duplicate entries for diagnostic ID between analyzer releases. Remove duplicate entries for diagnostic ID between analyzer releases. -## [RS2007](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Invalid entry in analyzer release file. - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS2007](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Invalid entry in analyzer release file. Invalid entry in analyzer release file. -## [RS2008](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Enable analyzer release tracking - |Item|Value| |-|-| |Category|MicrosoftCodeAnalysisReleaseTracking| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [RS2008](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Enable analyzer release tracking Enabling release tracking for analyzer packages helps in tracking and documenting the analyzer diagnostics that ship and/or change with each analyzer release. See details at https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md. +|Item|Value| +|-|-| +|Category|MicrosoftCodeAnalysisReleaseTracking| +|Enabled|True| +|Severity|Warning| +|CodeFix|True| +--- diff --git a/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md b/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md index d2df25186b..cb6951dc80 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md +++ b/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers.md b/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers.md index 4b180449a1..628982156f 100644 --- a/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers.md +++ b/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers.md @@ -2,40 +2,36 @@ ## [RS0030](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/BannedApiAnalyzers.Help.md): Do not used banned APIs +The symbol has been marked as banned in this project, and an alternate should be used instead. + |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -The symbol has been marked as banned in this project, and an alternate should be used instead. +--- ## [RS0031](https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/BannedApiAnalyzers.Help.md): The list of banned symbols contains a duplicate +The list of banned symbols contains a duplicate. + |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -The list of banned symbols contains a duplicate. +--- ## RS0035: External access to internal symbols outside the restricted namespace(s) is prohibited +RestrictedInternalsVisibleToAttribute enables a restricted version of InternalsVisibleToAttribute that limits access to internal symbols to those within specified namespaces. Each referencing assembly can only access internal symbols defined in the restricted namespaces that the referenced assembly allows. + |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Error| |CodeFix|False| - -### Rule description - -RestrictedInternalsVisibleToAttribute enables a restricted version of InternalsVisibleToAttribute that limits access to internal symbols to those within specified namespaces. Each referencing assembly can only access internal symbols defined in the restricted namespaces that the referenced assembly allows. - +--- diff --git a/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/RulesMissingDocumentation.md b/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/RulesMissingDocumentation.md index d2b9a2fbdb..f2d3e0059e 100644 --- a/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/RulesMissingDocumentation.md +++ b/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.md b/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.md index c8283356a3..9ccd3debe3 100644 --- a/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.md +++ b/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.md @@ -2,577 +2,523 @@ ## [CA1000](https://docs.microsoft.com/visualstudio/code-quality/ca1000): Do not declare static members on generic types +When a static member of a generic type is called, the type argument must be specified for the type. When a generic instance member that does not support inference is called, the type argument must be specified for the member. In these two cases, the syntax for specifying the type argument is different and easily confused. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -When a static member of a generic type is called, the type argument must be specified for the type. When a generic instance member that does not support inference is called, the type argument must be specified for the member. In these two cases, the syntax for specifying the type argument is different and easily confused. +--- ## [CA1001](https://docs.microsoft.com/visualstudio/code-quality/ca1001): Types that own disposable fields should be disposable +A class declares and implements an instance field that is a System.IDisposable type, and the class does not implement IDisposable. A class that declares an IDisposable field indirectly owns an unmanaged resource and should implement the IDisposable interface. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -A class declares and implements an instance field that is a System.IDisposable type, and the class does not implement IDisposable. A class that declares an IDisposable field indirectly owns an unmanaged resource and should implement the IDisposable interface. +--- ## [CA1002](https://docs.microsoft.com/visualstudio/code-quality/ca1002): Do not expose generic lists +System.Collections.Generic.List\ is a generic collection that's designed for performance and not inheritance. List\ does not contain virtual members that make it easier to change the behavior of an inherited class. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -System.Collections.Generic.List is a generic collection that's designed for performance and not inheritance. List does not contain virtual members that make it easier to change the behavior of an inherited class. +--- ## [CA1003](https://docs.microsoft.com/visualstudio/code-quality/ca1003): Use generic event handler instances +A type contains an event that declares an EventHandler delegate that returns void, whose signature contains two parameters (the first an object and the second a type that is assignable to EventArgs), and the containing assembly targets Microsoft .NET Framework?2.0. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A type contains an event that declares an EventHandler delegate that returns void, whose signature contains two parameters (the first an object and the second a type that is assignable to EventArgs), and the containing assembly targets Microsoft .NET Framework?2.0. +--- ## [CA1005](https://docs.microsoft.com/visualstudio/code-quality/ca1005): Avoid excessive parameters on generic types +The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. +--- ## [CA1008](https://docs.microsoft.com/visualstudio/code-quality/ca1008): Enums should have zero value +The default value of an uninitialized enumeration, just as other value types, is zero. A nonflags-attributed enumeration should define a member by using the value of zero so that the default value is a valid value of the enumeration. If an enumeration that has the FlagsAttribute attribute applied defines a zero-valued member, its name should be ""None"" to indicate that no values have been set in the enumeration. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -The default value of an uninitialized enumeration, just as other value types, is zero. A nonflags-attributed enumeration should define a member by using the value of zero so that the default value is a valid value of the enumeration. If an enumeration that has the FlagsAttribute attribute applied defines a zero-valued member, its name should be ""None"" to indicate that no values have been set in the enumeration. +--- ## [CA1010](https://docs.microsoft.com/visualstudio/code-quality/ca1010): Generic interface should also be implemented +To broaden the usability of a type, implement one of the generic interfaces. This is especially true for collections as they can then be used to populate generic collection types. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -To broaden the usability of a type, implement one of the generic interfaces. This is especially true for collections as they can then be used to populate generic collection types. +--- ## [CA1012](https://docs.microsoft.com/visualstudio/code-quality/ca1012): Abstract types should not have public constructors +Constructors on abstract types can be called only by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type that has a public constructor is incorrectly designed. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Constructors on abstract types can be called only by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type that has a public constructor is incorrectly designed. +--- ## [CA1014](https://docs.microsoft.com/visualstudio/code-quality/ca1014): Mark assemblies with CLSCompliant +The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages. Good design dictates that all assemblies explicitly indicate CLS compliance by using CLSCompliantAttribute . If this attribute is not present on an assembly, the assembly is not compliant. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages. Good design dictates that all assemblies explicitly indicate CLS compliance by using CLSCompliantAttribute . If this attribute is not present on an assembly, the assembly is not compliant. +--- ## [CA1016](https://docs.microsoft.com/visualstudio/code-quality/ca1016): Mark assemblies with assembly version +The .NET Framework uses the version number to uniquely identify an assembly, and to bind to types in strongly named assemblies. The version number is used together with version and publisher policy. By default, applications run only with the assembly version with which they were built. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -The .NET Framework uses the version number to uniquely identify an assembly, and to bind to types in strongly named assemblies. The version number is used together with version and publisher policy. By default, applications run only with the assembly version with which they were built. +--- ## [CA1017](https://docs.microsoft.com/visualstudio/code-quality/ca1017): Mark assemblies with ComVisible +ComVisibleAttribute determines how COM clients access managed code. Good design dictates that assemblies explicitly indicate COM visibility. COM visibility can be set for the whole assembly and then overridden for individual types and type members. If this attribute is not present, the contents of the assembly are visible to COM clients. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -ComVisibleAttribute determines how COM clients access managed code. Good design dictates that assemblies explicitly indicate COM visibility. COM visibility can be set for the whole assembly and then overridden for individual types and type members. If this attribute is not present, the contents of the assembly are visible to COM clients. +--- ## [CA1018](https://docs.microsoft.com/visualstudio/code-quality/ca1018): Mark attributes with AttributeUsageAttribute +Specify AttributeUsage on {0} + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Specify AttributeUsage on {0} +--- ## [CA1019](https://docs.microsoft.com/visualstudio/code-quality/ca1019): Define accessors for attribute arguments -|Item|Value| -|-|-| -|Category|Design| -|Enabled|False| -|Severity|Warning| -|CodeFix|True| - -### Rule description - Remove the property setter from {0} or reduce its accessibility because it corresponds to positional argument {1} -## [CA1021](https://docs.microsoft.com/visualstudio/code-quality/ca1021): Avoid out parameters - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1021](https://docs.microsoft.com/visualstudio/code-quality/ca1021): Avoid out parameters Passing types by reference (using 'out' or 'ref') requires experience with pointers, understanding how value types and reference types differ, and handling methods with multiple return values. Also, the difference between 'out' and 'ref' parameters is not widely understood. -## [CA1024](https://docs.microsoft.com/visualstudio/code-quality/ca1024): Use properties where appropriate - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1024](https://docs.microsoft.com/visualstudio/code-quality/ca1024): Use properties where appropriate A public or protected method has a name that starts with ""Get"", takes no parameters, and returns a value that is not an array. The method might be a good candidate to become a property. -## [CA1027](https://docs.microsoft.com/visualstudio/code-quality/ca1027): Mark enums with FlagsAttribute - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1027](https://docs.microsoft.com/visualstudio/code-quality/ca1027): Mark enums with FlagsAttribute An enumeration is a value type that defines a set of related named constants. Apply FlagsAttribute to an enumeration when its named constants can be meaningfully combined. -## [CA1028](https://docs.microsoft.com/visualstudio/code-quality/ca1028): Enum Storage should be Int32 - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1028](https://docs.microsoft.com/visualstudio/code-quality/ca1028): Enum Storage should be Int32 An enumeration is a value type that defines a set of related named constants. By default, the System.Int32 data type is used to store the constant value. Although you can change this underlying type, it is not required or recommended for most scenarios. -## [CA1030](https://docs.microsoft.com/visualstudio/code-quality/ca1030): Use events where appropriate - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1030](https://docs.microsoft.com/visualstudio/code-quality/ca1030): Use events where appropriate This rule detects methods that have names that ordinarily would be used for events. If a method is called in response to a clearly defined state change, the method should be invoked by an event handler. Objects that call the method should raise events instead of calling the method directly. -## [CA1031](https://docs.microsoft.com/visualstudio/code-quality/ca1031): Do not catch general exception types - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1031](https://docs.microsoft.com/visualstudio/code-quality/ca1031): Do not catch general exception types A general exception such as System.Exception or System.SystemException or a disallowed exception type is caught in a catch statement, or a general catch clause is used. General and disallowed exceptions should not be caught. -## [CA1032](https://docs.microsoft.com/visualstudio/code-quality/ca1032): Implement standard exception constructors - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1032](https://docs.microsoft.com/visualstudio/code-quality/ca1032): Implement standard exception constructors Failure to provide the full set of constructors can make it difficult to correctly handle exceptions. -## [CA1033](https://docs.microsoft.com/visualstudio/code-quality/ca1033): Interface methods should be callable by child types - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1033](https://docs.microsoft.com/visualstudio/code-quality/ca1033): Interface methods should be callable by child types An unsealed externally visible type provides an explicit method implementation of a public interface and does not provide an alternative externally visible method that has the same name. -## [CA1034](https://docs.microsoft.com/visualstudio/code-quality/ca1034): Nested types should not be visible - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1034](https://docs.microsoft.com/visualstudio/code-quality/ca1034): Nested types should not be visible A nested type is a type that is declared in the scope of another type. Nested types are useful to encapsulate private implementation details of the containing type. Used for this purpose, nested types should not be externally visible. -## [CA1036](https://docs.microsoft.com/visualstudio/code-quality/ca1036): Override methods on comparable types - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1036](https://docs.microsoft.com/visualstudio/code-quality/ca1036): Override methods on comparable types A public or protected type implements the System.IComparable interface. It does not override Object.Equals nor does it overload the language-specific operator for equality, inequality, less than, less than or equal, greater than or greater than or equal. -## [CA1040](https://docs.microsoft.com/visualstudio/code-quality/ca1040): Avoid empty interfaces - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1040](https://docs.microsoft.com/visualstudio/code-quality/ca1040): Avoid empty interfaces Interfaces define members that provide a behavior or usage contract. The functionality that is described by the interface can be adopted by any type, regardless of where the type appears in the inheritance hierarchy. A type implements an interface by providing implementations for the members of the interface. An empty interface does not define any members; therefore, it does not define a contract that can be implemented. -## [CA1041](https://docs.microsoft.com/visualstudio/code-quality/ca1041): Provide ObsoleteAttribute message - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1041](https://docs.microsoft.com/visualstudio/code-quality/ca1041): Provide ObsoleteAttribute message A type or member is marked by using a System.ObsoleteAttribute attribute that does not have its ObsoleteAttribute.Message property specified. When a type or member that is marked by using ObsoleteAttribute is compiled, the Message property of the attribute is displayed. This gives the user information about the obsolete type or member. -## [CA1043](https://docs.microsoft.com/visualstudio/code-quality/ca1043): Use Integral Or String Argument For Indexers - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1043](https://docs.microsoft.com/visualstudio/code-quality/ca1043): Use Integral Or String Argument For Indexers Indexers, that is, indexed properties, should use integer or string types for the index. These types are typically used for indexing data structures and increase the usability of the library. Use of the Object type should be restricted to those cases where the specific integer or string type cannot be specified at design time. If the design requires other types for the index, reconsider whether the type represents a logical data store. If it does not represent a logical data store, use a method. -## [CA1044](https://docs.microsoft.com/visualstudio/code-quality/ca1044): Properties should not be write only - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1044](https://docs.microsoft.com/visualstudio/code-quality/ca1044): Properties should not be write only Although it is acceptable and often necessary to have a read-only property, the design guidelines prohibit the use of write-only properties. This is because letting a user set a value, and then preventing the user from viewing that value, does not provide any security. Also, without read access, the state of shared objects cannot be viewed, which limits their usefulness. -## [CA1045](https://docs.microsoft.com/visualstudio/code-quality/ca1045): Do not pass types by reference - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1045](https://docs.microsoft.com/visualstudio/code-quality/ca1045): Do not pass types by reference Passing types by reference (using out or ref) requires experience with pointers, understanding how value types and reference types differ, and handling methods that have multiple return values. Also, the difference between out and ref parameters is not widely understood. -## [CA1046](https://docs.microsoft.com/visualstudio/code-quality/ca1046): Do not overload equality operator on reference types - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1046](https://docs.microsoft.com/visualstudio/code-quality/ca1046): Do not overload equality operator on reference types For reference types, the default implementation of the equality operator is almost always correct. By default, two references are equal only if they point to the same object. If the operator is providing meaningful value equality, the type should implement the generic 'System.IEquatable' interface. -## [CA1047](https://docs.microsoft.com/visualstudio/code-quality/ca1047): Do not declare protected member in sealed type - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1047](https://docs.microsoft.com/visualstudio/code-quality/ca1047): Do not declare protected member in sealed type Types declare protected members so that inheriting types can access or override the member. By definition, you cannot inherit from a sealed type, which means that protected methods on sealed types cannot be called. -## [CA1050](https://docs.microsoft.com/visualstudio/code-quality/ca1050): Declare types in namespaces - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1050](https://docs.microsoft.com/visualstudio/code-quality/ca1050): Declare types in namespaces Types are declared in namespaces to prevent name collisions and as a way to organize related types in an object hierarchy. -## [CA1051](https://docs.microsoft.com/visualstudio/code-quality/ca1051): Do not declare visible instance fields - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1051](https://docs.microsoft.com/visualstudio/code-quality/ca1051): Do not declare visible instance fields The primary use of a field should be as an implementation detail. Fields should be private or internal and should be exposed by using properties. -## [CA1052](https://docs.microsoft.com/visualstudio/code-quality/ca1052): Static holder types should be Static or NotInheritable - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1052](https://docs.microsoft.com/visualstudio/code-quality/ca1052): Static holder types should be Static or NotInheritable Type '{0}' is a static holder type but is neither static nor NotInheritable -## [CA1054](https://docs.microsoft.com/visualstudio/code-quality/ca1054): URI-like parameters should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1054](https://docs.microsoft.com/visualstudio/code-quality/ca1054): URI-like parameters should not be strings This rule assumes that the parameter represents a Uniform Resource Identifier (URI). A string representation or a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. 'System.Uri' class provides these services in a safe and secure manner. -## [CA1055](https://docs.microsoft.com/visualstudio/code-quality/ca1055): URI-like return values should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1055](https://docs.microsoft.com/visualstudio/code-quality/ca1055): URI-like return values should not be strings This rule assumes that the method returns a URI. A string representation of a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. The System.Uri class provides these services in a safe and secure manner. -## [CA1056](https://docs.microsoft.com/visualstudio/code-quality/ca1056): URI-like properties should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1056](https://docs.microsoft.com/visualstudio/code-quality/ca1056): URI-like properties should not be strings This rule assumes that the property represents a Uniform Resource Identifier (URI). A string representation of a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. The System.Uri class provides these services in a safe and secure manner. -## [CA1058](https://docs.microsoft.com/visualstudio/code-quality/ca1058): Types should not extend certain base types - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1058](https://docs.microsoft.com/visualstudio/code-quality/ca1058): Types should not extend certain base types An externally visible type extends certain base types. Use one of the alternatives. -## [CA1060](https://docs.microsoft.com/visualstudio/code-quality/ca1060): Move pinvokes to native methods class - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1060](https://docs.microsoft.com/visualstudio/code-quality/ca1060): Move pinvokes to native methods class Platform Invocation methods, such as those that are marked by using the System.Runtime.InteropServices.DllImportAttribute attribute, or methods that are defined by using the Declare keyword in Visual Basic, access unmanaged code. These methods should be of the NativeMethods, SafeNativeMethods, or UnsafeNativeMethods class. -## [CA1061](https://docs.microsoft.com/visualstudio/code-quality/ca1061): Do not hide base class methods - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1061](https://docs.microsoft.com/visualstudio/code-quality/ca1061): Do not hide base class methods A method in a base type is hidden by an identically named method in a derived type when the parameter signature of the derived method differs only by types that are more weakly derived than the corresponding types in the parameter signature of the base method. -## [CA1062](https://docs.microsoft.com/visualstudio/code-quality/ca1062): Validate arguments of public methods - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1062](https://docs.microsoft.com/visualstudio/code-quality/ca1062): Validate arguments of public methods An externally visible method dereferences one of its reference arguments without verifying whether that argument is null (Nothing in Visual Basic). All reference arguments that are passed to externally visible methods should be checked against null. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. If the method is designed to be called only by known assemblies, you should make the method internal. -## [CA1063](https://docs.microsoft.com/visualstudio/code-quality/ca1063): Implement IDisposable Correctly - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1063](https://docs.microsoft.com/visualstudio/code-quality/ca1063): Implement IDisposable Correctly All IDisposable types should implement the Dispose pattern correctly. -## [CA1064](https://docs.microsoft.com/visualstudio/code-quality/ca1064): Exceptions should be public - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1064](https://docs.microsoft.com/visualstudio/code-quality/ca1064): Exceptions should be public An internal exception is visible only inside its own internal scope. After the exception falls outside the internal scope, only the base exception can be used to catch the exception. If the internal exception is inherited from T:System.Exception, T:System.SystemException, or T:System.ApplicationException, the external code will not have sufficient information to know what to do with the exception. -## [CA1065](https://docs.microsoft.com/visualstudio/code-quality/ca1065): Do not raise exceptions in unexpected locations - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1065](https://docs.microsoft.com/visualstudio/code-quality/ca1065): Do not raise exceptions in unexpected locations A method that is not expected to throw exceptions throws an exception. -## [CA1066](https://docs.microsoft.com/visualstudio/code-quality/ca1066): Implement IEquatable when overriding Object.Equals - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| - -### Rule description +|CodeFix|False| +--- -When a type T overrides Object.Equals(object), the implementation must cast the object argument to the correct type T before performing the comparison. If the type implements IEquatable, and therefore offers the method T.Equals(T), and if the argument is known at compile time to be of type T, then the compiler can call IEquatable.Equals(T) instead of Object.Equals(object), and no cast is necessary, improving performance. +## [CA1066](https://docs.microsoft.com/visualstudio/code-quality/ca1066): Implement IEquatable when overriding Object.Equals -## [CA1067](https://docs.microsoft.com/visualstudio/code-quality/ca1067): Override Object.Equals(object) when implementing IEquatable +When a type T overrides Object.Equals(object), the implementation must cast the object argument to the correct type T before performing the comparison. If the type implements IEquatable\, and therefore offers the method T.Equals(T), and if the argument is known at compile time to be of type T, then the compiler can call IEquatable\.Equals(T) instead of Object.Equals(object), and no cast is necessary, improving performance. |Item|Value| |-|-| @@ -580,129 +526,131 @@ When a type T overrides Object.Equals(object), the implementation must cast the |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1067](https://docs.microsoft.com/visualstudio/code-quality/ca1067): Override Object.Equals(object) when implementing IEquatable\ -When a type T implements the interface IEquatable, it suggests to a user who sees a call to the Equals method in source code that an instance of the type can be equated with an instance of any other type. The user might be confused if their attempt to equate the type with an instance of another type fails to compile. This violates the "principle of least surprise". - -## [CA1068](https://docs.microsoft.com/visualstudio/code-quality/ca1068): CancellationToken parameters must come last +When a type T implements the interface IEquatable\, it suggests to a user who sees a call to the Equals method in source code that an instance of the type can be equated with an instance of any other type. The user might be confused if their attempt to equate the type with an instance of another type fails to compile. This violates the "principle of least surprise". |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1068](https://docs.microsoft.com/visualstudio/code-quality/ca1068): CancellationToken parameters must come last Method '{0}' should take CancellationToken as the last parameter -## [CA1069](https://docs.microsoft.com/visualstudio/code-quality/ca1069): Enums values should not be duplicated - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1069](https://docs.microsoft.com/visualstudio/code-quality/ca1069): Enums values should not be duplicated The field reference '{0}' is duplicated in this bitwise initialization -## [CA1070](https://docs.microsoft.com/visualstudio/code-quality/ca1070): Do not declare event fields as virtual - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1070](https://docs.microsoft.com/visualstudio/code-quality/ca1070): Do not declare event fields as virtual Do not declare virtual events in a base class. Overridden events in a derived class have undefined behavior. The C# compiler does not handle this correctly and it is unpredictable whether a subscriber to the derived event will actually be subscribing to the base class event. -## [CA1200](https://docs.microsoft.com/visualstudio/code-quality/ca1200): Avoid using cref tags with a prefix - |Item|Value| |-|-| -|Category|Documentation| +|Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1200](https://docs.microsoft.com/visualstudio/code-quality/ca1200): Avoid using cref tags with a prefix Use of cref tags with prefixes should be avoided, since it prevents the compiler from verifying references and the IDE from updating references during refactorings. It is permissible to suppress this error at a single documentation site if the cref must use a prefix because the type being mentioned is not findable by the compiler. For example, if a cref is mentioning a special attribute in the full framework but you're in a file that compiles against the portable framework, or if you want to reference a type at higher layer of Roslyn, you should suppress the error. You should not suppress the error just because you want to take a shortcut and avoid using the full syntax. -## [CA1303](https://docs.microsoft.com/visualstudio/code-quality/ca1303): Do not pass literals as localized parameters - |Item|Value| |-|-| -|Category|Globalization| +|Category|Documentation| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1303](https://docs.microsoft.com/visualstudio/code-quality/ca1303): Do not pass literals as localized parameters A method passes a string literal as a parameter to a constructor or method in the .NET Framework class library and that string should be localizable. To fix a violation of this rule, replace the string literal with a string retrieved through an instance of the ResourceManager class. -## [CA1304](https://docs.microsoft.com/visualstudio/code-quality/ca1304): Specify CultureInfo - |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1304](https://docs.microsoft.com/visualstudio/code-quality/ca1304): Specify CultureInfo A method or constructor calls a member that has an overload that accepts a System.Globalization.CultureInfo parameter, and the method or constructor does not call the overload that takes the CultureInfo parameter. When a CultureInfo or System.IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'CultureInfo' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'. -## [CA1305](https://docs.microsoft.com/visualstudio/code-quality/ca1305): Specify IFormatProvider - |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1305](https://docs.microsoft.com/visualstudio/code-quality/ca1305): Specify IFormatProvider A method or constructor calls one or more members that have overloads that accept a System.IFormatProvider parameter, and the method or constructor does not call the overload that takes the IFormatProvider parameter. When a System.Globalization.CultureInfo or IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be based on the input from/output displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider'. Otherwise, if the result will be stored and accessed by software, such as when it is loaded from disk/database and when it is persisted to disk/database, specify 'CultureInfo.InvariantCulture'. -## [CA1307](https://docs.microsoft.com/visualstudio/code-quality/ca1307): Specify StringComparison - |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1307](https://docs.microsoft.com/visualstudio/code-quality/ca1307): Specify StringComparison for clarity -A string comparison operation uses a method overload that does not set a StringComparison parameter. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. +A string comparison operation uses a method overload that does not set a StringComparison parameter. It is recommended to use the overload with StringComparison parameter for clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. + +|Item|Value| +|-|-| +|Category|Globalization| +|Enabled|False| +|Severity|Warning| +|CodeFix|False| +--- ## [CA1308](https://docs.microsoft.com/visualstudio/code-quality/ca1308): Normalize strings to uppercase +Strings should be normalized to uppercase. A small group of characters cannot make a round trip when they are converted to lowercase. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -Strings should be normalized to uppercase. A small group of characters cannot make a round trip when they are converted to lowercase. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters. +## [CA1309](https://docs.microsoft.com/visualstudio/code-quality/ca1309): Use ordinal string comparison -## [CA1309](https://docs.microsoft.com/visualstudio/code-quality/ca1309): Use ordinal stringcomparison +A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable. |Item|Value| |-|-| @@ -710,25 +658,35 @@ Strings should be normalized to uppercase. A small group of characters cannot ma |Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1310](https://docs.microsoft.com/visualstudio/code-quality/ca1310): Specify StringComparison for correctness -A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable. +A string comparison operation uses a method overload that does not set a StringComparison parameter, hence its behavior could vary based on the current user's locale settings. It is strongly recommended to use the overload with StringComparison parameter for correctness and clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. + +|Item|Value| +|-|-| +|Category|Globalization| +|Enabled|True| +|Severity|Warning| +|CodeFix|False| +--- ## [CA1401](https://docs.microsoft.com/visualstudio/code-quality/ca1401): P/Invokes should not be visible +A public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic). Such methods should not be exposed. + |Item|Value| |-|-| |Category|Interoperability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -A public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic). Such methods should not be exposed. +## [CA1416](https://docs.microsoft.com/visualstudio/code-quality/ca1416): Validate platform compatibility -## [CA1417](https://docs.microsoft.com/visualstudio/code-quality/ca1417): Do not use 'OutAttribute' on string parameters for P/Invokes +Using platform dependent API on a component makes the code no longer work across all platforms. |Item|Value| |-|-| @@ -736,649 +694,599 @@ A public or protected method in a public type has the System.Runtime.InteropServ |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1417](https://docs.microsoft.com/visualstudio/code-quality/ca1417): Do not use 'OutAttribute' on string parameters for P/Invokes String parameters passed by value with the 'OutAttribute' can destabilize the runtime if the string is an interned string. -## [CA1501](https://docs.microsoft.com/visualstudio/code-quality/ca1501): Avoid excessive inheritance - |Item|Value| |-|-| -|Category|Maintainability| -|Enabled|False| +|Category|Interoperability| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1501](https://docs.microsoft.com/visualstudio/code-quality/ca1501): Avoid excessive inheritance Deeply nested type hierarchies can be difficult to follow, understand, and maintain. This rule limits analysis to hierarchies in the same module. To fix a violation of this rule, derive the type from a base type that is less deep in the inheritance hierarchy or eliminate some of the intermediate base types. -## [CA1502](https://docs.microsoft.com/visualstudio/code-quality/ca1502): Avoid excessive complexity - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1502](https://docs.microsoft.com/visualstudio/code-quality/ca1502): Avoid excessive complexity Cyclomatic complexity measures the number of linearly independent paths through the method, which is determined by the number and complexity of conditional branches. A low cyclomatic complexity generally indicates a method that is easy to understand, test, and maintain. The cyclomatic complexity is calculated from a control flow graph of the method and is given as follows: `cyclomatic complexity = the number of edges - the number of nodes + 1`, where a node represents a logic branch point and an edge represents a line between nodes. -## [CA1505](https://docs.microsoft.com/visualstudio/code-quality/ca1505): Avoid unmaintainable code - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1505](https://docs.microsoft.com/visualstudio/code-quality/ca1505): Avoid unmaintainable code The maintainability index is calculated by using the following metrics: lines of code, program volume, and cyclomatic complexity. Program volume is a measure of the difficulty of understanding of a symbol that is based on the number of operators and operands in the code. Cyclomatic complexity is a measure of the structural complexity of the type or method. A low maintainability index indicates that code is probably difficult to maintain and would be a good candidate to redesign. -## [CA1506](https://docs.microsoft.com/visualstudio/code-quality/ca1506): Avoid excessive class coupling - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1506](https://docs.microsoft.com/visualstudio/code-quality/ca1506): Avoid excessive class coupling This rule measures class coupling by counting the number of unique type references that a symbol contains. Symbols that have a high degree of class coupling can be difficult to maintain. It is a good practice to have types and methods that exhibit low coupling and high cohesion. To fix this violation, try to redesign the code to reduce the number of types to which it is coupled. -## [CA1507](https://docs.microsoft.com/visualstudio/code-quality/ca1507): Use nameof to express symbol names - |Item|Value| |-|-| |Category|Maintainability| -|Enabled|True| +|Enabled|False| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1507](https://docs.microsoft.com/visualstudio/code-quality/ca1507): Use nameof to express symbol names Using nameof helps keep your code valid when refactoring. -## [CA1508](https://docs.microsoft.com/visualstudio/code-quality/ca1508): Avoid dead conditional code - |Item|Value| |-|-| |Category|Maintainability| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1508](https://docs.microsoft.com/visualstudio/code-quality/ca1508): Avoid dead conditional code '{0}' is never '{1}'. Remove or refactor the condition(s) to avoid dead code. -## [CA1509](https://docs.microsoft.com/visualstudio/code-quality/ca1509): Invalid entry in code metrics rule specification file - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1509](https://docs.microsoft.com/visualstudio/code-quality/ca1509): Invalid entry in code metrics rule specification file Invalid entry in code metrics rule specification file. -## [CA1700](https://docs.microsoft.com/visualstudio/code-quality/ca1700): Do not name enum values 'Reserved' - |Item|Value| |-|-| -|Category|Naming| +|Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1700](https://docs.microsoft.com/visualstudio/code-quality/ca1700): Do not name enum values 'Reserved' This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change. -## [CA1707](https://docs.microsoft.com/visualstudio/code-quality/ca1707): Identifiers should not contain underscores - |Item|Value| |-|-| |Category|Naming| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1707](https://docs.microsoft.com/visualstudio/code-quality/ca1707): Identifiers should not contain underscores By convention, identifier names do not contain the underscore (_) character. This rule checks namespaces, types, members, and parameters. -## [CA1708](https://docs.microsoft.com/visualstudio/code-quality/ca1708): Identifiers should differ by more than case - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1708](https://docs.microsoft.com/visualstudio/code-quality/ca1708): Identifiers should differ by more than case Identifiers for namespaces, types, members, and parameters cannot differ only by case because languages that target the common language runtime are not required to be case-sensitive. -## [CA1710](https://docs.microsoft.com/visualstudio/code-quality/ca1710): Identifiers should have correct suffix - |Item|Value| |-|-| |Category|Naming| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1710](https://docs.microsoft.com/visualstudio/code-quality/ca1710): Identifiers should have correct suffix By convention, the names of types that extend certain base types or that implement certain interfaces, or types that are derived from these types, have a suffix that is associated with the base type or interface. -## [CA1711](https://docs.microsoft.com/visualstudio/code-quality/ca1711): Identifiers should not have incorrect suffix - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1711](https://docs.microsoft.com/visualstudio/code-quality/ca1711): Identifiers should not have incorrect suffix By convention, only the names of types that extend certain base types or that implement certain interfaces, or types that are derived from these types, should end with specific reserved suffixes. Other type names should not use these reserved suffixes. -## [CA1712](https://docs.microsoft.com/visualstudio/code-quality/ca1712): Do not prefix enum values with type name - |Item|Value| |-|-| |Category|Naming| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1712](https://docs.microsoft.com/visualstudio/code-quality/ca1712): Do not prefix enum values with type name An enumeration's values should not start with the type name of the enumeration. -## [CA1713](https://docs.microsoft.com/visualstudio/code-quality/ca1713): Events should not have 'Before' or 'After' prefix - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1713](https://docs.microsoft.com/visualstudio/code-quality/ca1713): Events should not have 'Before' or 'After' prefix Event names should describe the action that raises the event. To name related events that are raised in a specific sequence, use the present or past tense to indicate the relative position in the sequence of actions. For example, when naming a pair of events that is raised when closing a resource, you might name it 'Closing' and 'Closed', instead of 'BeforeClose' and 'AfterClose'. -## [CA1714](https://docs.microsoft.com/visualstudio/code-quality/ca1714): Flags enums should have plural names - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1714](https://docs.microsoft.com/visualstudio/code-quality/ca1714): Flags enums should have plural names A public enumeration has the System.FlagsAttribute attribute, and its name does not end in ""s"". Types that are marked by using FlagsAttribute have names that are plural because the attribute indicates that more than one value can be specified. -## [CA1715](https://docs.microsoft.com/visualstudio/code-quality/ca1715): Identifiers should have correct prefix - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1715](https://docs.microsoft.com/visualstudio/code-quality/ca1715): Identifiers should have correct prefix The name of an externally visible interface does not start with an uppercase ""I"". The name of a generic type parameter on an externally visible type or method does not start with an uppercase ""T"". -## [CA1716](https://docs.microsoft.com/visualstudio/code-quality/ca1716): Identifiers should not match keywords - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1716](https://docs.microsoft.com/visualstudio/code-quality/ca1716): Identifiers should not match keywords A namespace name or a type name matches a reserved keyword in a programming language. Identifiers for namespaces and types should not match keywords that are defined by languages that target the common language runtime. -## [CA1717](https://docs.microsoft.com/visualstudio/code-quality/ca1717): Only FlagsAttribute enums should have plural names - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1717](https://docs.microsoft.com/visualstudio/code-quality/ca1717): Only FlagsAttribute enums should have plural names Naming conventions dictate that a plural name for an enumeration indicates that more than one value of the enumeration can be specified at the same time. -## [CA1720](https://docs.microsoft.com/visualstudio/code-quality/ca1720): Identifier contains type name - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1720](https://docs.microsoft.com/visualstudio/code-quality/ca1720): Identifier contains type name Names of parameters and members are better used to communicate their meaning than to describe their type, which is expected to be provided by development tools. For names of members, if a data type name must be used, use a language-independent name instead of a language-specific one. -## [CA1721](https://docs.microsoft.com/visualstudio/code-quality/ca1721): Property names should not match get methods - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1721](https://docs.microsoft.com/visualstudio/code-quality/ca1721): Property names should not match get methods The name of a public or protected member starts with ""Get"" and otherwise matches the name of a public or protected property. ""Get"" methods and properties should have names that clearly distinguish their function. -## [CA1724](https://docs.microsoft.com/visualstudio/code-quality/ca1724): Type names should not match namespaces - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1724](https://docs.microsoft.com/visualstudio/code-quality/ca1724): Type names should not match namespaces Type names should not match the names of namespaces that are defined in the .NET Framework class library. Violating this rule can reduce the usability of the library. -## [CA1725](https://docs.microsoft.com/visualstudio/code-quality/ca1725): Parameter names should match base declaration - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1725](https://docs.microsoft.com/visualstudio/code-quality/ca1725): Parameter names should match base declaration Consistent naming of parameters in an override hierarchy increases the usability of the method overrides. A parameter name in a derived method that differs from the name in the base declaration can cause confusion about whether the method is an override of the base method or a new overload of the method. -## [CA1801](https://docs.microsoft.com/visualstudio/code-quality/ca1801): Review unused parameters - |Item|Value| |-|-| -|Category|Usage| -|Enabled|True| +|Category|Naming| +|Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1801](https://docs.microsoft.com/visualstudio/code-quality/ca1801): Review unused parameters Avoid unused paramereters in your code. If the parameter cannot be removed, then change its name so it starts with an underscore and is optionally followed by an integer, such as '_', '_1', '_2', etc. These are treated as special discard symbol names. -## [CA1802](https://docs.microsoft.com/visualstudio/code-quality/ca1802): Use literals where appropriate - |Item|Value| |-|-| -|Category|Performance| +|Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1802](https://docs.microsoft.com/visualstudio/code-quality/ca1802): Use literals where appropriate A field is declared static and read-only (Shared and ReadOnly in Visual Basic), and is initialized by using a value that is computable at compile time. Because the value that is assigned to the targeted field is computable at compile time, change the declaration to a const (Const in Visual Basic) field so that the value is computed at compile time instead of at run?time. -## [CA1805](https://docs.microsoft.com/visualstudio/code-quality/ca1805): Do not initialize unnecessarily - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1805](https://docs.microsoft.com/visualstudio/code-quality/ca1805): Do not initialize unnecessarily The .NET runtime initializes all fields of reference types to their default values before running the constructor. In most cases, explicitly initializing a field to its default value in a constructor is redundant, adding maintenance costs and potentially degrading performance (such as with increased assembly size), and the explicit initialization can be removed. In some cases, such as with static readonly fields that permanently retain their default value, consider instead changing them to be constants or properties. -## [CA1806](https://docs.microsoft.com/visualstudio/code-quality/ca1806): Do not ignore method results - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1806](https://docs.microsoft.com/visualstudio/code-quality/ca1806): Do not ignore method results A new object is created but never used; or a method that creates and returns a new string is called and the new string is never used; or a COM or P/Invoke method returns an HRESULT or error code that is never used. -## [CA1810](https://docs.microsoft.com/visualstudio/code-quality/ca1810): Initialize reference type static fields inline - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1810](https://docs.microsoft.com/visualstudio/code-quality/ca1810): Initialize reference type static fields inline A reference type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. -## [CA1812](https://docs.microsoft.com/visualstudio/code-quality/ca1812): Avoid uninstantiated internal classes - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1812](https://docs.microsoft.com/visualstudio/code-quality/ca1812): Avoid uninstantiated internal classes An instance of an assembly-level type is not created by code in the assembly. -## [CA1813](https://docs.microsoft.com/visualstudio/code-quality/ca1813): Avoid unsealed attributes - |Item|Value| |-|-| |Category|Performance| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1813](https://docs.microsoft.com/visualstudio/code-quality/ca1813): Avoid unsealed attributes The .NET Framework class library provides methods for retrieving custom attributes. By default, these methods search the attribute inheritance hierarchy. Sealing the attribute eliminates the search through the inheritance hierarchy and can improve performance. -## [CA1814](https://docs.microsoft.com/visualstudio/code-quality/ca1814): Prefer jagged arrays over multidimensional - |Item|Value| |-|-| |Category|Performance| -|Enabled|True| +|Enabled|False| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1814](https://docs.microsoft.com/visualstudio/code-quality/ca1814): Prefer jagged arrays over multidimensional A jagged array is an array whose elements are arrays. The arrays that make up the elements can be of different sizes, leading to less wasted space for some sets of data. -## [CA1815](https://docs.microsoft.com/visualstudio/code-quality/ca1815): Override equals and operator equals on value types - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1815](https://docs.microsoft.com/visualstudio/code-quality/ca1815): Override equals and operator equals on value types For value types, the inherited implementation of Equals uses the Reflection library and compares the contents of all fields. Reflection is computationally expensive, and comparing every field for equality might be unnecessary. If you expect users to compare or sort instances, or to use instances as hash table keys, your value type should implement Equals. -## [CA1816](https://docs.microsoft.com/visualstudio/code-quality/ca1816): Dispose methods should call SuppressFinalize - |Item|Value| |-|-| -|Category|Usage| +|Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1816](https://docs.microsoft.com/visualstudio/code-quality/ca1816): Dispose methods should call SuppressFinalize A method that is an implementation of Dispose does not call GC.SuppressFinalize; or a method that is not an implementation of Dispose calls GC.SuppressFinalize; or a method calls GC.SuppressFinalize and passes something other than this (Me in Visual?Basic). -## [CA1819](https://docs.microsoft.com/visualstudio/code-quality/ca1819): Properties should not return arrays - |Item|Value| |-|-| -|Category|Performance| +|Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1819](https://docs.microsoft.com/visualstudio/code-quality/ca1819): Properties should not return arrays Arrays that are returned by properties are not write-protected, even when the property is read-only. To keep the array tamper-proof, the property must return a copy of the array. Typically, users will not understand the adverse performance implications of calling such a property. -## [CA1820](https://docs.microsoft.com/visualstudio/code-quality/ca1820): Test for empty strings using string length - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1820](https://docs.microsoft.com/visualstudio/code-quality/ca1820): Test for empty strings using string length Comparing strings by using the String.Length property or the String.IsNullOrEmpty method is significantly faster than using Equals. -## [CA1821](https://docs.microsoft.com/visualstudio/code-quality/ca1821): Remove empty Finalizers - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1821](https://docs.microsoft.com/visualstudio/code-quality/ca1821): Remove empty Finalizers Finalizers should be avoided where possible, to avoid the additional performance overhead involved in tracking object lifetime. -## [CA1822](https://docs.microsoft.com/visualstudio/code-quality/ca1822): Mark members as static - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1822](https://docs.microsoft.com/visualstudio/code-quality/ca1822): Mark members as static Members that do not access instance data or call instance methods can be marked as static. After you mark the methods as static, the compiler will emit nonvirtual call sites to these members. This can give you a measurable performance gain for performance-sensitive code. -## [CA1823](https://docs.microsoft.com/visualstudio/code-quality/ca1823): Avoid unused private fields - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1823](https://docs.microsoft.com/visualstudio/code-quality/ca1823): Avoid unused private fields Private fields were detected that do not appear to be accessed in the assembly. -## [CA1824](https://docs.microsoft.com/visualstudio/code-quality/ca1824): Mark assemblies with NeutralResourcesLanguageAttribute - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1824](https://docs.microsoft.com/visualstudio/code-quality/ca1824): Mark assemblies with NeutralResourcesLanguageAttribute The NeutralResourcesLanguage attribute informs the ResourceManager of the language that was used to display the resources of a neutral culture for an assembly. This improves lookup performance for the first resource that you load and can reduce your working set. -## [CA1825](https://docs.microsoft.com/visualstudio/code-quality/ca1825): Avoid zero-length array allocations - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1825](https://docs.microsoft.com/visualstudio/code-quality/ca1825): Avoid zero-length array allocations Avoid unnecessary zero-length array allocations. Use {0} instead. -## [CA1826](https://docs.microsoft.com/visualstudio/code-quality/ca1826): Do not use Enumerable methods on indexable collections - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1826](https://docs.microsoft.com/visualstudio/code-quality/ca1826): Do not use Enumerable methods on indexable collections This collection is directly indexable. Going through LINQ here causes unnecessary allocations and CPU work. -## [CA1827](https://docs.microsoft.com/visualstudio/code-quality/ca1827): Do not use Count() or LongCount() when Any() can be used - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1827](https://docs.microsoft.com/visualstudio/code-quality/ca1827): Do not use Count() or LongCount() when Any() can be used For non-empty collections, Count() and LongCount() enumerate the entire sequence, while Any() stops at the first item or the first item that satisfies a condition. -## [CA1828](https://docs.microsoft.com/visualstudio/code-quality/ca1828): Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1828](https://docs.microsoft.com/visualstudio/code-quality/ca1828): Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used For non-empty collections, CountAsync() and LongCountAsync() enumerate the entire sequence, while AnyAsync() stops at the first item or the first item that satisfies a condition. -## [CA1829](https://docs.microsoft.com/visualstudio/code-quality/ca1829): Use Length/Count property instead of Count() when available - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1829](https://docs.microsoft.com/visualstudio/code-quality/ca1829): Use Length/Count property instead of Count() when available Enumerable.Count() potentially enumerates the sequence while a Length/Count property is a direct access. -## [CA1830](https://docs.microsoft.com/visualstudio/code-quality/ca1830): Prefer strongly-typed Append and Insert method overloads on StringBuilder - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1830](https://docs.microsoft.com/visualstudio/code-quality/ca1830): Prefer strongly-typed Append and Insert method overloads on StringBuilder StringBuilder.Append and StringBuilder.Insert provide overloads for multiple types beyond System.String. When possible, prefer the strongly-typed overloads over using ToString() and the string-based overload. -## [CA1831](https://docs.microsoft.com/visualstudio/code-quality/ca1831): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1831](https://docs.microsoft.com/visualstudio/code-quality/ca1831): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on string values produces a copy of requested portion of the string. This copy is usually unnecessary when it is implicitly used as a ReadOnlySpan or ReadOnlyMemory value. Use the AsSpan method to avoid the unnecessary copy. -## [CA1832](https://docs.microsoft.com/visualstudio/code-quality/ca1832): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1832](https://docs.microsoft.com/visualstudio/code-quality/ca1832): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on array values produces a copy of requested portion of the array. This copy is usually unnecessary when it is implicitly used as a ReadOnlySpan or ReadOnlyMemory value. Use the AsSpan method to avoid the unnecessary copy. -## [CA1833](https://docs.microsoft.com/visualstudio/code-quality/ca1833): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1833](https://docs.microsoft.com/visualstudio/code-quality/ca1833): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on array values produces a copy of requested portion of the array. This copy is often unwanted when it is implicitly used as a Span or Memory value. Use the AsSpan method to avoid the copy. -## [CA1834](https://docs.microsoft.com/visualstudio/code-quality/ca1834): Consider using 'StringBuilder.Append(char)' when applicable - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1834](https://docs.microsoft.com/visualstudio/code-quality/ca1834): Consider using 'StringBuilder.Append(char)' when applicable 'StringBuilder.Append(char)' is more efficient than 'StringBuilder.Append(string)' when the string is a single character. When calling 'Append' with a constant, prefer using a constant char rather than a constant string containing one character. -## [CA1835](https://docs.microsoft.com/visualstudio/code-quality/ca1835): Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description - -'Stream' has a 'ReadAsync' overload that takes a 'Memory' as the first argument, and a 'WriteAsync' overload that takes a 'ReadOnlyMemory' as the first argument. Prefer calling the memory based overloads, which are more efficient. +## [CA1835](https://docs.microsoft.com/visualstudio/code-quality/ca1835): Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' -## [CA1836](https://docs.microsoft.com/visualstudio/code-quality/ca1836): Prefer IsEmpty over Count +'Stream' has a 'ReadAsync' overload that takes a 'Memory\' as the first argument, and a 'WriteAsync' overload that takes a 'ReadOnlyMemory\' as the first argument. Prefer calling the memory based overloads, which are more efficient. |Item|Value| |-|-| @@ -1386,155 +1294,155 @@ The Range-based indexer on array values produces a copy of requested portion of |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1836](https://docs.microsoft.com/visualstudio/code-quality/ca1836): Prefer IsEmpty over Count For determining whether the object contains or not any items, prefer using 'IsEmpty' property rather than retrieving the number of items from the 'Count' property and comparing it to 0 or 1. -## [CA1837](https://docs.microsoft.com/visualstudio/code-quality/ca1837): Use 'Environment.ProcessId' - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1837](https://docs.microsoft.com/visualstudio/code-quality/ca1837): Use 'Environment.ProcessId' 'Environment.ProcessId' is simpler and faster than 'Process.GetCurrentProcess().Id'. +|Item|Value| +|-|-| +|Category|Performance| +|Enabled|True| +|Severity|Warning| +|CodeFix|True| +--- + ## [CA1838](https://docs.microsoft.com/visualstudio/code-quality/ca1838): Avoid 'StringBuilder' parameters for P/Invokes +Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. +--- ## [CA2000](https://docs.microsoft.com/visualstudio/code-quality/ca2000): Dispose objects before losing scope +If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead. +--- ## [CA2002](https://docs.microsoft.com/visualstudio/code-quality/ca2002): Do not lock on objects with weak identity +An object is said to have a weak identity when it can be directly accessed across application domain boundaries. A thread that tries to acquire a lock on an object that has a weak identity can be blocked by a second thread in a different application domain that has a lock on the same object. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -An object is said to have a weak identity when it can be directly accessed across application domain boundaries. A thread that tries to acquire a lock on an object that has a weak identity can be blocked by a second thread in a different application domain that has a lock on the same object. +--- ## [CA2007](https://docs.microsoft.com/visualstudio/code-quality/ca2007): Consider calling ConfigureAwait on the awaited task +When an asynchronous method awaits a Task directly, continuation occurs in the same thread that created the task. Consider calling Task.ConfigureAwait(Boolean) to signal your intention for continuation. Call ConfigureAwait(false) on the task to schedule continuations to the thread pool, thereby avoiding a deadlock on the UI thread. Passing false is a good option for app-independent libraries. Calling ConfigureAwait(true) on the task has the same behavior as not explicitly calling ConfigureAwait. By explicitly calling this method, you're letting readers know you intentionally want to perform the continuation on the original synchronization context. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -When an asynchronous method awaits a Task directly, continuation occurs in the same thread that created the task. Consider calling Task.ConfigureAwait(Boolean) to signal your intention for continuation. Call ConfigureAwait(false) on the task to schedule continuations to the thread pool, thereby avoiding a deadlock on the UI thread. Passing false is a good option for app-independent libraries. Calling ConfigureAwait(true) on the task has the same behavior as not explicitly calling ConfigureAwait. By explicitly calling this method, you're letting readers know you intentionally want to perform the continuation on the original synchronization context. +--- ## [CA2008](https://docs.microsoft.com/visualstudio/code-quality/ca2008): Do not create tasks without passing a TaskScheduler +Do not create tasks unless you are using one of the overloads that takes a TaskScheduler. The default is to schedule on TaskScheduler.Current, which would lead to deadlocks. Either use TaskScheduler.Default to schedule on the thread pool, or explicitly pass TaskScheduler.Current to make your intentions clear. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Do not create tasks unless you are using one of the overloads that takes a TaskScheduler. The default is to schedule on TaskScheduler.Current, which would lead to deadlocks. Either use TaskScheduler.Default to schedule on the thread pool, or explicitly pass TaskScheduler.Current to make your intentions clear. +--- ## [CA2009](https://docs.microsoft.com/visualstudio/code-quality/ca2009): Do not call ToImmutableCollection on an ImmutableCollection value +Do not call {0} on an {1} value + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Do not call {0} on an {1} value +--- ## [CA2011](https://docs.microsoft.com/visualstudio/code-quality/ca2011): Avoid infinite recursion +Do not assign the property within its setter. This call might result in an infinite recursion. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Do not assign the property within its setter. This call might result in an infinite recursion. +--- ## [CA2012](https://docs.microsoft.com/visualstudio/code-quality/ca2012): Use ValueTasks correctly +ValueTasks returned from member invocations are intended to be directly awaited. Attempts to consume a ValueTask multiple times or to directly access one's result before it's known to be completed may result in an exception or corruption. Ignoring such a ValueTask is likely an indication of a functional bug and may degrade performance. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -ValueTasks returned from member invocations are intended to be directly awaited. Attempts to consume a ValueTask multiple times or to directly access one's result before it's known to be completed may result in an exception or corruption. Ignoring such a ValueTask is likely an indication of a functional bug and may degrade performance. +--- ## [CA2013](https://docs.microsoft.com/visualstudio/code-quality/ca2013): Do not use ReferenceEquals with value types +Value type typed arguments are uniquely boxed for each call to this method, therefore the result is always false. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Value type typed arguments are uniquely boxed for each call to this method, therefore the result is always false. +--- ## [CA2014](https://docs.microsoft.com/visualstudio/code-quality/ca2014): Do not use stackalloc in loops +Stack space allocated by a stackalloc is only released at the end of the current method's invocation. Using it in a loop can result in unbounded stack growth and eventual stack overflow conditions. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -Stack space allocated by a stackalloc is only released at the end of the current method's invocation. Using it in a loop can result in unbounded stack growth and eventual stack overflow conditions. +## [CA2015](https://docs.microsoft.com/visualstudio/code-quality/ca2015): Do not define finalizers for types derived from MemoryManager\ -## [CA2015](https://docs.microsoft.com/visualstudio/code-quality/ca2015): Do not define finalizers for types derived from MemoryManager +Adding a finalizer to a type derived from MemoryManager\ may permit memory to be freed while it is still in use by a Span\. |Item|Value| |-|-| @@ -1542,727 +1450,659 @@ Stack space allocated by a stackalloc is only released at the end of the current |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Adding a finalizer to a type derived from MemoryManager may permit memory to be freed while it is still in use by a Span. +--- ## [CA2016](https://docs.microsoft.com/visualstudio/code-quality/ca2016): Forward the 'CancellationToken' parameter to methods that take one +Forward the 'CancellationToken' parameter to methods that take one to ensure the operation cancellation notifications gets properly propagated, or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Forward the 'CancellationToken' parameter to methods that take one to ensure the operation cancellation notifications gets properly propagated, or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token. +--- ## [CA2100](https://docs.microsoft.com/visualstudio/code-quality/ca2100): Review SQL queries for security vulnerabilities +SQL queries that directly use user input can be vulnerable to SQL injection attacks. Review this SQL query for potential vulnerabilities, and consider using a parameterized SQL query. + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -SQL queries that directly use user input can be vulnerable to SQL injection attacks. Review this SQL query for potential vulnerabilities, and consider using a parameterized SQL query. +--- ## [CA2101](https://docs.microsoft.com/visualstudio/code-quality/ca2101): Specify marshaling for P/Invoke string arguments +A platform invoke member allows partially trusted callers, has a string parameter, and does not explicitly marshal the string. This can cause a potential security vulnerability. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -A platform invoke member allows partially trusted callers, has a string parameter, and does not explicitly marshal the string. This can cause a potential security vulnerability. +--- ## [CA2109](https://docs.microsoft.com/visualstudio/code-quality/ca2109): Review visible event handlers +A public or protected event-handling method was detected. Event-handling methods should not be exposed unless absolutely necessary. + |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A public or protected event-handling method was detected. Event-handling methods should not be exposed unless absolutely necessary. +--- ## [CA2119](https://docs.microsoft.com/visualstudio/code-quality/ca2119): Seal methods that satisfy private interfaces +An inheritable public type provides an overridable method implementation of an internal (Friend in Visual Basic) interface. To fix a violation of this rule, prevent the method from being overridden outside the assembly. + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -An inheritable public type provides an overridable method implementation of an internal (Friend in Visual Basic) interface. To fix a violation of this rule, prevent the method from being overridden outside the assembly. +--- ## [CA2153](https://docs.microsoft.com/visualstudio/code-quality/ca2153): Do Not Catch Corrupted State Exceptions +Catching corrupted state exceptions could mask errors (such as access violations), resulting in inconsistent state of execution or making it easier for attackers to compromise system. Instead, catch and handle a more specific set of exception type(s) or re-throw the exception. + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Catching corrupted state exceptions could mask errors (such as access violations), resulting in inconsistent state of execution or making it easier for attackers to compromise system. Instead, catch and handle a more specific set of exception type(s) or re-throw the exception. +--- ## [CA2200](https://docs.microsoft.com/visualstudio/code-quality/ca2200): Rethrow to preserve stack details +Re-throwing caught exception changes stack information + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Re-throwing caught exception changes stack information +--- ## [CA2201](https://docs.microsoft.com/visualstudio/code-quality/ca2201): Do not raise reserved exception types -|Item|Value| -|-|-| -|Category|Usage| -|Enabled|False| -|Severity|Warning| -|CodeFix|False| - -### Rule description - An exception of type that is not sufficiently specific or reserved by the runtime should never be raised by user code. This makes the original error difficult to detect and debug. If this exception instance might be thrown, use a different exception type. -## [CA2207](https://docs.microsoft.com/visualstudio/code-quality/ca2207): Initialize value type static fields inline - |Item|Value| |-|-| |Category|Usage| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2207](https://docs.microsoft.com/visualstudio/code-quality/ca2207): Initialize value type static fields inline A value type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. -## [CA2208](https://docs.microsoft.com/visualstudio/code-quality/ca2208): Instantiate argument exceptions correctly - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2208](https://docs.microsoft.com/visualstudio/code-quality/ca2208): Instantiate argument exceptions correctly A call is made to the default (parameterless) constructor of an exception type that is or derives from ArgumentException, or an incorrect string argument is passed to a parameterized constructor of an exception type that is or derives from ArgumentException. -## [CA2211](https://docs.microsoft.com/visualstudio/code-quality/ca2211): Non-constant fields should not be visible - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2211](https://docs.microsoft.com/visualstudio/code-quality/ca2211): Non-constant fields should not be visible Static fields that are neither constants nor read-only are not thread-safe. Access to such a field must be carefully controlled and requires advanced programming techniques to synchronize access to the class object. -## [CA2213](https://docs.microsoft.com/visualstudio/code-quality/ca2213): Disposable fields should be disposed - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2213](https://docs.microsoft.com/visualstudio/code-quality/ca2213): Disposable fields should be disposed A type that implements System.IDisposable declares fields that are of types that also implement IDisposable. The Dispose method of the field is not called by the Dispose method of the declaring type. To fix a violation of this rule, call Dispose on fields that are of types that implement IDisposable if you are responsible for allocating and releasing the unmanaged resources held by the field. -## [CA2214](https://docs.microsoft.com/visualstudio/code-quality/ca2214): Do not call overridable methods in constructors - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2214](https://docs.microsoft.com/visualstudio/code-quality/ca2214): Do not call overridable methods in constructors Virtual methods defined on the class should not be called from constructors. If a derived class has overridden the method, the derived class version will be called (before the derived class constructor is called). -## [CA2215](https://docs.microsoft.com/visualstudio/code-quality/ca2215): Dispose methods should call base class dispose - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2215](https://docs.microsoft.com/visualstudio/code-quality/ca2215): Dispose methods should call base class dispose A type that implements System.IDisposable inherits from a type that also implements IDisposable. The Dispose method of the inheriting type does not call the Dispose method of the parent type. To fix a violation of this rule, call base.Dispose in your Dispose method. -## [CA2216](https://docs.microsoft.com/visualstudio/code-quality/ca2216): Disposable types should declare finalizer - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2216](https://docs.microsoft.com/visualstudio/code-quality/ca2216): Disposable types should declare finalizer A type that implements System.IDisposable and has fields that suggest the use of unmanaged resources does not implement a finalizer, as described by Object.Finalize. -## [CA2217](https://docs.microsoft.com/visualstudio/code-quality/ca2217): Do not mark enums with FlagsAttribute - |Item|Value| |-|-| |Category|Usage| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2217](https://docs.microsoft.com/visualstudio/code-quality/ca2217): Do not mark enums with FlagsAttribute An externally visible enumeration is marked by using FlagsAttribute, and it has one or more values that are not powers of two or a combination of the other defined values on the enumeration. -## [CA2218](https://docs.microsoft.com/visualstudio/code-quality/ca2218): Override GetHashCode on overriding Equals - |Item|Value| |-|-| |Category|Usage| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2218](https://docs.microsoft.com/visualstudio/code-quality/ca2218): Override GetHashCode on overriding Equals GetHashCode returns a value, based on the current instance, that is suited for hashing algorithms and data structures such as a hash table. Two objects that are the same type and are equal must return the same hash code. -## [CA2219](https://docs.microsoft.com/visualstudio/code-quality/ca2219): Do not raise exceptions in finally clauses - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2219](https://docs.microsoft.com/visualstudio/code-quality/ca2219): Do not raise exceptions in finally clauses When an exception is raised in a finally clause, the new exception hides the active exception. This makes the original error difficult to detect and debug. -## [CA2224](https://docs.microsoft.com/visualstudio/code-quality/ca2224): Override Equals on overloading operator equals - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2224](https://docs.microsoft.com/visualstudio/code-quality/ca2224): Override Equals on overloading operator equals A public type implements the equality operator but does not override Object.Equals. -## [CA2225](https://docs.microsoft.com/visualstudio/code-quality/ca2225): Operator overloads have named alternates - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2225](https://docs.microsoft.com/visualstudio/code-quality/ca2225): Operator overloads have named alternates An operator overload was detected, and the expected named alternative method was not found. The named alternative member provides access to the same functionality as the operator and is provided for developers who program in languages that do not support overloaded operators. -## [CA2226](https://docs.microsoft.com/visualstudio/code-quality/ca2226): Operators should have symmetrical overloads - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2226](https://docs.microsoft.com/visualstudio/code-quality/ca2226): Operators should have symmetrical overloads A type implements the equality or inequality operator and does not implement the opposite operator. -## [CA2227](https://docs.microsoft.com/visualstudio/code-quality/ca2227): Collection properties should be read only - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2227](https://docs.microsoft.com/visualstudio/code-quality/ca2227): Collection properties should be read only A writable collection property allows a user to replace the collection with a different collection. A read-only property stops the collection from being replaced but still allows the individual members to be set. -## [CA2229](https://docs.microsoft.com/visualstudio/code-quality/ca2229): Implement serialization constructors - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2229](https://docs.microsoft.com/visualstudio/code-quality/ca2229): Implement serialization constructors To fix a violation of this rule, implement the serialization constructor. For a sealed class, make the constructor private; otherwise, make it protected. -## [CA2231](https://docs.microsoft.com/visualstudio/code-quality/ca2231): Overload operator equals on overriding value type Equals - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2231](https://docs.microsoft.com/visualstudio/code-quality/ca2231): Overload operator equals on overriding value type Equals In most programming languages there is no default implementation of the equality operator (==) for value types. If your programming language supports operator overloads, you should consider implementing the equality operator. Its behavior should be identical to that of Equals. -## [CA2234](https://docs.microsoft.com/visualstudio/code-quality/ca2234): Pass system uri objects instead of strings - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2234](https://docs.microsoft.com/visualstudio/code-quality/ca2234): Pass system uri objects instead of strings A call is made to a method that has a string parameter whose name contains "uri", "URI", "urn", "URN", "url", or "URL". The declaring type of the method contains a corresponding method overload that has a System.Uri parameter. -## [CA2235](https://docs.microsoft.com/visualstudio/code-quality/ca2235): Mark all non-serializable fields - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2235](https://docs.microsoft.com/visualstudio/code-quality/ca2235): Mark all non-serializable fields An instance field of a type that is not serializable is declared in a type that is serializable. -## [CA2237](https://docs.microsoft.com/visualstudio/code-quality/ca2237): Mark ISerializable types with serializable - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2237](https://docs.microsoft.com/visualstudio/code-quality/ca2237): Mark ISerializable types with serializable To be recognized by the common language runtime as serializable, types must be marked by using the SerializableAttribute attribute even when the type uses a custom serialization routine through implementation of the ISerializable interface. -## [CA2241](https://docs.microsoft.com/visualstudio/code-quality/ca2241): Provide correct arguments to formatting methods - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2241](https://docs.microsoft.com/visualstudio/code-quality/ca2241): Provide correct arguments to formatting methods The format argument that is passed to System.String.Format does not contain a format item that corresponds to each object argument, or vice versa. -## [CA2242](https://docs.microsoft.com/visualstudio/code-quality/ca2242): Test for NaN correctly - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2242](https://docs.microsoft.com/visualstudio/code-quality/ca2242): Test for NaN correctly This expression tests a value against Single.Nan or Double.Nan. Use Single.IsNan(Single) or Double.IsNan(Double) to test the value. -## [CA2243](https://docs.microsoft.com/visualstudio/code-quality/ca2243): Attribute string literals should parse correctly - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2243](https://docs.microsoft.com/visualstudio/code-quality/ca2243): Attribute string literals should parse correctly The string literal parameter of an attribute does not parse correctly for a URL, a GUID, or a version. -## [CA2244](https://docs.microsoft.com/visualstudio/code-quality/ca2244): Do not duplicate indexed element initializations - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2244](https://docs.microsoft.com/visualstudio/code-quality/ca2244): Do not duplicate indexed element initializations Indexed elements in objects initializers must initialize unique elements. A duplicate index might overwrite a previous element initialization. -## [CA2245](https://docs.microsoft.com/visualstudio/code-quality/ca2245): Do not assign a property to itself - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2245](https://docs.microsoft.com/visualstudio/code-quality/ca2245): Do not assign a property to itself The property {0} should not be assigned to itself -## [CA2246](https://docs.microsoft.com/visualstudio/code-quality/ca2246): Assigning symbol and its member in the same statement - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2246](https://docs.microsoft.com/visualstudio/code-quality/ca2246): Assigning symbol and its member in the same statement Assigning to a symbol and its member (field/property) in the same statement is not recommended. It is not clear if the member access was intended to use symbol's old value prior to the assignment or new value from the assignment in this statement. For clarity, consider splitting the assignments into separate statements. -## [CA2247](https://docs.microsoft.com/visualstudio/code-quality/ca2247): Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2247](https://docs.microsoft.com/visualstudio/code-quality/ca2247): Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum TaskCompletionSource has constructors that take TaskCreationOptions that control the underlying Task, and constructors that take object state that's stored in the task. Accidentally passing a TaskContinuationOptions instead of a TaskCreationOptions will result in the call treating the options as state. -## [CA2248](https://docs.microsoft.com/visualstudio/code-quality/ca2248): Provide correct 'enum' argument to 'Enum.HasFlag' - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2248](https://docs.microsoft.com/visualstudio/code-quality/ca2248): Provide correct 'enum' argument to 'Enum.HasFlag' 'Enum.HasFlag' method expects the 'enum' argument to be of the same 'enum' type as the instance on which the method is invoked and that this 'enum' is marked with 'System.FlagsAttribute'. If these are different 'enum' types, an unhandled exception will be thrown at runtime. If the 'enum' type is not marked with 'System.FlagsAttribute' the call will always return 'false' at runtime. -## [CA2249](https://docs.microsoft.com/visualstudio/code-quality/ca2249): Consider using 'string.Contains' instead of 'string.IndexOf' - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2249](https://docs.microsoft.com/visualstudio/code-quality/ca2249): Consider using 'string.Contains' instead of 'string.IndexOf' Calls to 'string.IndexOf' where the result is used to check for the presence/absence of a substring can be replaced by 'string.Contains'. -## [CA2300](https://docs.microsoft.com/visualstudio/code-quality/ca2300): Do not use insecure deserializer BinaryFormatter - |Item|Value| |-|-| -|Category|Security| -|Enabled|False| +|Category|Usage| +|Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2300](https://docs.microsoft.com/visualstudio/code-quality/ca2300): Do not use insecure deserializer BinaryFormatter The method '{0}' is insecure when deserializing untrusted data. If you need to instead detect BinaryFormatter deserialization without a SerializationBinder set, then disable rule CA2300, and enable rules CA2301 and CA2302. -## [CA2301](https://docs.microsoft.com/visualstudio/code-quality/ca2301): Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2301](https://docs.microsoft.com/visualstudio/code-quality/ca2301): Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2302](https://docs.microsoft.com/visualstudio/code-quality/ca2302): Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2302](https://docs.microsoft.com/visualstudio/code-quality/ca2302): Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2305](https://docs.microsoft.com/visualstudio/code-quality/ca2305): Do not use insecure deserializer LosFormatter - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2305](https://docs.microsoft.com/visualstudio/code-quality/ca2305): Do not use insecure deserializer LosFormatter The method '{0}' is insecure when deserializing untrusted data. -## [CA2310](https://docs.microsoft.com/visualstudio/code-quality/ca2310): Do not use insecure deserializer NetDataContractSerializer - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2310](https://docs.microsoft.com/visualstudio/code-quality/ca2310): Do not use insecure deserializer NetDataContractSerializer The method '{0}' is insecure when deserializing untrusted data. If you need to instead detect NetDataContractSerializer deserialization without a SerializationBinder set, then disable rule CA2310, and enable rules CA2311 and CA2312. -## [CA2311](https://docs.microsoft.com/visualstudio/code-quality/ca2311): Do not deserialize without first setting NetDataContractSerializer.Binder - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2311](https://docs.microsoft.com/visualstudio/code-quality/ca2311): Do not deserialize without first setting NetDataContractSerializer.Binder The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2312](https://docs.microsoft.com/visualstudio/code-quality/ca2312): Ensure NetDataContractSerializer.Binder is set before deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2312](https://docs.microsoft.com/visualstudio/code-quality/ca2312): Ensure NetDataContractSerializer.Binder is set before deserializing The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2315](https://docs.microsoft.com/visualstudio/code-quality/ca2315): Do not use insecure deserializer ObjectStateFormatter - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2315](https://docs.microsoft.com/visualstudio/code-quality/ca2315): Do not use insecure deserializer ObjectStateFormatter The method '{0}' is insecure when deserializing untrusted data. -## [CA2321](https://docs.microsoft.com/visualstudio/code-quality/ca2321): Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2321](https://docs.microsoft.com/visualstudio/code-quality/ca2321): Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver The method '{0}' is insecure when deserializing untrusted data with a JavaScriptSerializer initialized with a SimpleTypeResolver. Initialize JavaScriptSerializer without a JavaScriptTypeResolver specified, or initialize with a JavaScriptTypeResolver that limits the types of objects in the deserialized object graph. -## [CA2322](https://docs.microsoft.com/visualstudio/code-quality/ca2322): Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2322](https://docs.microsoft.com/visualstudio/code-quality/ca2322): Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing The method '{0}' is insecure when deserializing untrusted data with a JavaScriptSerializer initialized with a SimpleTypeResolver. Ensure that the JavaScriptSerializer is initialized without a JavaScriptTypeResolver specified, or initialized with a JavaScriptTypeResolver that limits the types of objects in the deserialized object graph. -## [CA2326](https://docs.microsoft.com/visualstudio/code-quality/ca2326): Do not use TypeNameHandling values other than None - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2326](https://docs.microsoft.com/visualstudio/code-quality/ca2326): Do not use TypeNameHandling values other than None Deserializing JSON when using a TypeNameHandling value other than None can be insecure. If you need to instead detect Json.NET deserialization when a SerializationBinder isn't specified, then disable rule CA2326, and enable rules CA2327, CA2328, CA2329, and CA2330. -## [CA2327](https://docs.microsoft.com/visualstudio/code-quality/ca2327): Do not use insecure JsonSerializerSettings - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2327](https://docs.microsoft.com/visualstudio/code-quality/ca2327): Do not use insecure JsonSerializerSettings When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using JsonSerializerSettings, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2328](https://docs.microsoft.com/visualstudio/code-quality/ca2328): Ensure that JsonSerializerSettings are secure - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2328](https://docs.microsoft.com/visualstudio/code-quality/ca2328): Ensure that JsonSerializerSettings are secure When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using JsonSerializerSettings, ensure TypeNameHandling.None is specified, or for values other than None, ensure a SerializationBinder is specified to restrict deserialized types. -## [CA2329](https://docs.microsoft.com/visualstudio/code-quality/ca2329): Do not deserialize with JsonSerializer using an insecure configuration - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2329](https://docs.microsoft.com/visualstudio/code-quality/ca2329): Do not deserialize with JsonSerializer using an insecure configuration When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using deserializing JsonSerializer, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2330](https://docs.microsoft.com/visualstudio/code-quality/ca2330): Ensure that JsonSerializer has a secure configuration when deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2330](https://docs.microsoft.com/visualstudio/code-quality/ca2330): Ensure that JsonSerializer has a secure configuration when deserializing When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using deserializing JsonSerializer, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2350](https://docs.microsoft.com/visualstudio/code-quality/ca2350): Do not use DataTable.ReadXml() with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2350](https://docs.microsoft.com/visualstudio/code-quality/ca2350): Do not use DataTable.ReadXml() with untrusted data The method '{0}' is insecure when deserializing untrusted data -## [CA2351](https://docs.microsoft.com/visualstudio/code-quality/ca2351): Do not use DataSet.ReadXml() with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2351](https://docs.microsoft.com/visualstudio/code-quality/ca2351): Do not use DataSet.ReadXml() with untrusted data The method '{0}' is insecure when deserializing untrusted data -## [CA2352](https://docs.microsoft.com/visualstudio/code-quality/ca2352): Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2352](https://docs.microsoft.com/visualstudio/code-quality/ca2352): Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks When deserializing untrusted input with an IFormatter-based serializer, deserializing a {0} object is insecure. '{1}' either is or derives from {0}. -## [CA2353](https://docs.microsoft.com/visualstudio/code-quality/ca2353): Unsafe DataSet or DataTable in serializable type - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} +## [CA2353](https://docs.microsoft.com/visualstudio/code-quality/ca2353): Unsafe DataSet or DataTable in serializable type -## [CA2354](https://docs.microsoft.com/visualstudio/code-quality/ca2354): Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks +When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} |Item|Value| |-|-| @@ -2270,246 +2110,227 @@ When deserializing untrusted input, deserializing a {0} object is insecure. '{1} |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2354](https://docs.microsoft.com/visualstudio/code-quality/ca2354): Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2355](https://docs.microsoft.com/visualstudio/code-quality/ca2355): Unsafe DataSet or DataTable type found in deserializable object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2355](https://docs.microsoft.com/visualstudio/code-quality/ca2355): Unsafe DataSet or DataTable type found in deserializable object graph When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2356](https://docs.microsoft.com/visualstudio/code-quality/ca2356): Unsafe DataSet or DataTable type in web deserializable object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2356](https://docs.microsoft.com/visualstudio/code-quality/ca2356): Unsafe DataSet or DataTable type in web deserializable object graph When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2361](https://docs.microsoft.com/visualstudio/code-quality/ca2361): Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2361](https://docs.microsoft.com/visualstudio/code-quality/ca2361): Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data The method '{0}' is insecure when deserializing untrusted data. Make sure that autogenerated class containing the '{0}' call is not deserialized with untrusted data. -## [CA2362](https://docs.microsoft.com/visualstudio/code-quality/ca2362): Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2362](https://docs.microsoft.com/visualstudio/code-quality/ca2362): Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks When deserializing untrusted input with an IFormatter-based serializer, deserializing a {0} object is insecure. '{1}' either is or derives from {0}. Ensure that the autogenerated type is never deserialized with untrusted data. -## [CA3001](https://docs.microsoft.com/visualstudio/code-quality/ca3001): Review code for SQL injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3001](https://docs.microsoft.com/visualstudio/code-quality/ca3001): Review code for SQL injection vulnerabilities Potential SQL injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3002](https://docs.microsoft.com/visualstudio/code-quality/ca3002): Review code for XSS vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3002](https://docs.microsoft.com/visualstudio/code-quality/ca3002): Review code for XSS vulnerabilities Potential cross-site scripting (XSS) vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3003](https://docs.microsoft.com/visualstudio/code-quality/ca3003): Review code for file path injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3003](https://docs.microsoft.com/visualstudio/code-quality/ca3003): Review code for file path injection vulnerabilities Potential file path injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3004](https://docs.microsoft.com/visualstudio/code-quality/ca3004): Review code for information disclosure vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3004](https://docs.microsoft.com/visualstudio/code-quality/ca3004): Review code for information disclosure vulnerabilities Potential information disclosure vulnerability was found where '{0}' in method '{1}' may contain unintended information from '{2}' in method '{3}'. -## [CA3005](https://docs.microsoft.com/visualstudio/code-quality/ca3005): Review code for LDAP injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3005](https://docs.microsoft.com/visualstudio/code-quality/ca3005): Review code for LDAP injection vulnerabilities Potential LDAP injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3006](https://docs.microsoft.com/visualstudio/code-quality/ca3006): Review code for process command injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3006](https://docs.microsoft.com/visualstudio/code-quality/ca3006): Review code for process command injection vulnerabilities Potential process command injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3007](https://docs.microsoft.com/visualstudio/code-quality/ca3007): Review code for open redirect vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3007](https://docs.microsoft.com/visualstudio/code-quality/ca3007): Review code for open redirect vulnerabilities Potential open redirect vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3008](https://docs.microsoft.com/visualstudio/code-quality/ca3008): Review code for XPath injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3008](https://docs.microsoft.com/visualstudio/code-quality/ca3008): Review code for XPath injection vulnerabilities Potential XPath injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3009](https://docs.microsoft.com/visualstudio/code-quality/ca3009): Review code for XML injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3009](https://docs.microsoft.com/visualstudio/code-quality/ca3009): Review code for XML injection vulnerabilities Potential XML injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3010](https://docs.microsoft.com/visualstudio/code-quality/ca3010): Review code for XAML injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3010](https://docs.microsoft.com/visualstudio/code-quality/ca3010): Review code for XAML injection vulnerabilities Potential XAML injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3011](https://docs.microsoft.com/visualstudio/code-quality/ca3011): Review code for DLL injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3011](https://docs.microsoft.com/visualstudio/code-quality/ca3011): Review code for DLL injection vulnerabilities Potential DLL injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3012](https://docs.microsoft.com/visualstudio/code-quality/ca3012): Review code for regex injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3012](https://docs.microsoft.com/visualstudio/code-quality/ca3012): Review code for regex injection vulnerabilities Potential regex injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3061](https://docs.microsoft.com/visualstudio/code-quality/ca3061): Do Not Add Schema By URL - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3061](https://docs.microsoft.com/visualstudio/code-quality/ca3061): Do Not Add Schema By URL This overload of XmlSchemaCollection.Add method internally enables DTD processing on the XML reader instance used, and uses UrlResolver for resolving external XML entities. The outcome is information disclosure. Content from file system or network shares for the machine processing the XML can be exposed to attacker. In addition, an attacker can use this as a DoS vector. -## [CA3075](https://docs.microsoft.com/visualstudio/code-quality/ca3075): Insecure DTD processing in XML - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when invoking XmlReader.Create(), setting the InnerXml property of the XmlDocument and enabling DTD processing using XmlUrlResolver insecurely can lead to information disclosure. Replace it with a call to the Load() method overload that takes an XmlReader instance, use XmlReader.Create() to accept XmlReaderSettings arguments or consider explicitly setting secure values. The DataViewSettingCollectionString property of DataViewManager should always be assigned from a trusted source, the DtdProcessing property should be set to false, and the XmlResolver property should be changed to XmlSecureResolver or null.  +## [CA3075](https://docs.microsoft.com/visualstudio/code-quality/ca3075): Insecure DTD processing in XML -## [CA3076](https://docs.microsoft.com/visualstudio/code-quality/ca3076): Insecure XSLT script processing. +Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when invoking XmlReader.Create(), setting the InnerXml property of the XmlDocument and enabling DTD processing using XmlUrlResolver insecurely can lead to information disclosure. Replace it with a call to the Load() method overload that takes an XmlReader instance, use XmlReader.Create() to accept XmlReaderSettings arguments or consider explicitly setting secure values. The DataViewSettingCollectionString property of DataViewManager should always be assigned from a trusted source, the DtdProcessing property should be set to false, and the XmlResolver property should be changed to XmlSecureResolver or null. |Item|Value| |-|-| @@ -2517,25 +2338,23 @@ Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3076](https://docs.microsoft.com/visualstudio/code-quality/ca3076): Insecure XSLT script processing. Providing an insecure XsltSettings instance and an insecure XmlResolver instance to XslCompiledTransform.Load method is potentially unsafe as it allows processing script within XSL, which on an untrusted XSL input may lead to malicious code execution. Either replace the insecure XsltSettings argument with XsltSettings.Default or an instance that has disabled document function and script execution, or replace the XmlResolver argurment with null or an XmlSecureResolver instance. This message may be suppressed if the input is known to be from a trusted source and external resource resolution from locations that are not known in advance must be supported. -## [CA3077](https://docs.microsoft.com/visualstudio/code-quality/ca3077): Insecure Processing in API Design, XmlDocument and XmlTextReader - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocument and using XmlUrlResolver for resolving external XML entities may lead to information disclosure. Ensure to set the XmlResolver property to null, create an instance of XmlSecureResolver when processing untrusted input, or use XmlReader.Create method with a secure XmlReaderSettings argument. Unless you need to enable it, ensure the DtdProcessing property is set to false.  +## [CA3077](https://docs.microsoft.com/visualstudio/code-quality/ca3077): Insecure Processing in API Design, XmlDocument and XmlTextReader -## [CA3147](https://docs.microsoft.com/visualstudio/code-quality/ca3147): Mark Verb Handlers With Validate Antiforgery Token +Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocument and using XmlUrlResolver for resolving external XML entities may lead to information disclosure. Ensure to set the XmlResolver property to null, create an instance of XmlSecureResolver when processing untrusted input, or use XmlReader.Create method with a secure XmlReaderSettings argument. Unless you need to enable it, ensure the DtdProcessing property is set to false. |Item|Value| |-|-| @@ -2543,671 +2362,628 @@ Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocu |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3147](https://docs.microsoft.com/visualstudio/code-quality/ca3147): Mark Verb Handlers With Validate Antiforgery Token Missing ValidateAntiForgeryTokenAttribute on controller action {0} -## [CA5350](https://docs.microsoft.com/visualstudio/code-quality/ca5350): Do Not Use Weak Cryptographic Algorithms - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5350](https://docs.microsoft.com/visualstudio/code-quality/ca5350): Do Not Use Weak Cryptographic Algorithms Cryptographic algorithms degrade over time as attacks become for advances to attacker get access to more computation. Depending on the type and application of this cryptographic algorithm, further degradation of the cryptographic strength of it may allow attackers to read enciphered messages, tamper with enciphered  messages, forge digital signatures, tamper with hashed content, or otherwise compromise any cryptosystem based on this algorithm. Replace encryption uses with the AES algorithm (AES-256, AES-192 and AES-128 are acceptable) with a key length greater than or equal to 128 bits. Replace hashing uses with a hashing function in the SHA-2 family, such as SHA-2 512, SHA-2 384, or SHA-2 256. -## [CA5351](https://docs.microsoft.com/visualstudio/code-quality/ca5351): Do Not Use Broken Cryptographic Algorithms - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5351](https://docs.microsoft.com/visualstudio/code-quality/ca5351): Do Not Use Broken Cryptographic Algorithms An attack making it computationally feasible to break this algorithm exists. This allows attackers to break the cryptographic guarantees it is designed to provide. Depending on the type and application of this cryptographic algorithm, this may allow attackers to read enciphered messages, tamper with enciphered  messages, forge digital signatures, tamper with hashed content, or otherwise compromise any cryptosystem based on this algorithm. Replace encryption uses with the AES algorithm (AES-256, AES-192 and AES-128 are acceptable) with a key length greater than or equal to 128 bits. Replace hashing uses with a hashing function in the SHA-2 family, such as SHA512, SHA384, or SHA256. Replace digital signature uses with RSA with a key length greater than or equal to 2048-bits, or ECDSA with a key length greater than or equal to 256 bits. -## [CA5358](https://docs.microsoft.com/visualstudio/code-quality/ca5358): Review cipher mode usage with cryptography experts - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5358](https://docs.microsoft.com/visualstudio/code-quality/ca5358): Review cipher mode usage with cryptography experts These cipher modes might be vulnerable to attacks. Consider using recommended modes (CBC, CTS). -## [CA5359](https://docs.microsoft.com/visualstudio/code-quality/ca5359): Do Not Disable Certificate Validation - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5359](https://docs.microsoft.com/visualstudio/code-quality/ca5359): Do Not Disable Certificate Validation A certificate can help authenticate the identity of the server. Clients should validate the server certificate to ensure requests are sent to the intended server. If the ServerCertificateValidationCallback always returns 'true', any certificate will pass validation. -## [CA5360](https://docs.microsoft.com/visualstudio/code-quality/ca5360): Do Not Call Dangerous Methods In Deserialization - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5360](https://docs.microsoft.com/visualstudio/code-quality/ca5360): Do Not Call Dangerous Methods In Deserialization Insecure Deserialization is a vulnerability which occurs when untrusted data is used to abuse the logic of an application, inflict a Denial-of-Service (DoS) attack, or even execute arbitrary code upon it being deserialized. It’s frequently possible for malicious users to abuse these deserialization features when the application is deserializing untrusted data which is under their control. Specifically, invoke dangerous methods in the process of deserialization. Successful insecure deserialization attacks could allow an attacker to carry out attacks such as DoS attacks, authentication bypasses, and remote code execution. -## [CA5361](https://docs.microsoft.com/visualstudio/code-quality/ca5361): Do Not Disable SChannel Use of Strong Crypto - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5361](https://docs.microsoft.com/visualstudio/code-quality/ca5361): Do Not Disable SChannel Use of Strong Crypto Starting with the .NET Framework 4.6, the System.Net.ServicePointManager and System.Net.Security.SslStream classes are recommeded to use new protocols. The old ones have protocol weaknesses and are not supported. Setting Switch.System.Net.DontEnableSchUseStrongCrypto with true will use the old weak crypto check and opt out of the protocol migration. -## [CA5362](https://docs.microsoft.com/visualstudio/code-quality/ca5362): Potential reference cycle in deserialized object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5362](https://docs.microsoft.com/visualstudio/code-quality/ca5362): Potential reference cycle in deserialized object graph Review code that processes untrusted deserialized data for handling of unexpected reference cycles. An unexpected reference cycle should not cause the code to enter an infinite loop. Otherwise, an unexpected reference cycle can allow an attacker to DOS or exhaust the memory of the process when deserializing untrusted data. -## [CA5363](https://docs.microsoft.com/visualstudio/code-quality/ca5363): Do Not Disable Request Validation - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5363](https://docs.microsoft.com/visualstudio/code-quality/ca5363): Do Not Disable Request Validation Request validation is a feature in ASP.NET that examines HTTP requests and determines whether they contain potentially dangerous content. This check adds protection from markup or code in the URL query string, cookies, or posted form values that might have been added for malicious purposes. So, it is generally desirable and should be left enabled for defense in depth. -## [CA5364](https://docs.microsoft.com/visualstudio/code-quality/ca5364): Do Not Use Deprecated Security Protocols - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5364](https://docs.microsoft.com/visualstudio/code-quality/ca5364): Do Not Use Deprecated Security Protocols Using a deprecated security protocol rather than the system default is risky. -## [CA5365](https://docs.microsoft.com/visualstudio/code-quality/ca5365): Do Not Disable HTTP Header Checking - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5365](https://docs.microsoft.com/visualstudio/code-quality/ca5365): Do Not Disable HTTP Header Checking HTTP header checking enables encoding of the carriage return and newline characters, \r and \n, that are found in response headers. This encoding can help to avoid injection attacks that exploit an application that echoes untrusted data contained by the header. -## [CA5366](https://docs.microsoft.com/visualstudio/code-quality/ca5366): Use XmlReader For DataSet Read Xml - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5366](https://docs.microsoft.com/visualstudio/code-quality/ca5366): Use XmlReader For DataSet Read Xml Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5367](https://docs.microsoft.com/visualstudio/code-quality/ca5367): Do Not Serialize Types With Pointer Fields - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5367](https://docs.microsoft.com/visualstudio/code-quality/ca5367): Do Not Serialize Types With Pointer Fields Pointers are not "type safe" in the sense that you cannot guarantee the correctness of the memory they point at. So, serializing types with pointer fields is dangerous, as it may allow an attacker to control the pointer. -## [CA5368](https://docs.microsoft.com/visualstudio/code-quality/ca5368): Set ViewStateUserKey For Classes Derived From Page - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5368](https://docs.microsoft.com/visualstudio/code-quality/ca5368): Set ViewStateUserKey For Classes Derived From Page Setting the ViewStateUserKey property can help you prevent attacks on your application by allowing you to assign an identifier to the view-state variable for individual users so that they cannot use the variable to generate an attack. Otherwise, there will be cross-site request forgery vulnerabilities. -## [CA5369](https://docs.microsoft.com/visualstudio/code-quality/ca5369): Use XmlReader For Deserialize - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5369](https://docs.microsoft.com/visualstudio/code-quality/ca5369): Use XmlReader For Deserialize Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5370](https://docs.microsoft.com/visualstudio/code-quality/ca5370): Use XmlReader For Validating Reader - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5370](https://docs.microsoft.com/visualstudio/code-quality/ca5370): Use XmlReader For Validating Reader Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5371](https://docs.microsoft.com/visualstudio/code-quality/ca5371): Use XmlReader For Schema Read - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5371](https://docs.microsoft.com/visualstudio/code-quality/ca5371): Use XmlReader For Schema Read Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5372](https://docs.microsoft.com/visualstudio/code-quality/ca5372): Use XmlReader For XPathDocument - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5372](https://docs.microsoft.com/visualstudio/code-quality/ca5372): Use XmlReader For XPathDocument Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5373](https://docs.microsoft.com/visualstudio/code-quality/ca5373): Do not use obsolete key derivation function - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5373](https://docs.microsoft.com/visualstudio/code-quality/ca5373): Do not use obsolete key derivation function Password-based key derivation should use PBKDF2 with SHA-2. Avoid using PasswordDeriveBytes since it generates a PBKDF1 key. Avoid using Rfc2898DeriveBytes.CryptDeriveKey since it doesn't use the iteration count or salt. -## [CA5374](https://docs.microsoft.com/visualstudio/code-quality/ca5374): Do Not Use XslTransform - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5374](https://docs.microsoft.com/visualstudio/code-quality/ca5374): Do Not Use XslTransform Do not use XslTransform. It does not restrict potentially dangerous external references. -## [CA5375](https://docs.microsoft.com/visualstudio/code-quality/ca5375): Do Not Use Account Shared Access Signature - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5375](https://docs.microsoft.com/visualstudio/code-quality/ca5375): Do Not Use Account Shared Access Signature Shared Access Signatures(SAS) are a vital part of the security model for any application using Azure Storage, they should provide limited and safe permissions to your storage account to clients that don't have the account key. All of the operations available via a service SAS are also available via an account SAS, that is, account SAS is too powerful. So it is recommended to use Service SAS to delegate access more carefully. -## [CA5376](https://docs.microsoft.com/visualstudio/code-quality/ca5376): Use SharedAccessProtocol HttpsOnly - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5376](https://docs.microsoft.com/visualstudio/code-quality/ca5376): Use SharedAccessProtocol HttpsOnly HTTPS encrypts network traffic. Use HttpsOnly, rather than HttpOrHttps, to ensure network traffic is always encrypted to help prevent disclosure of sensitive data. -## [CA5377](https://docs.microsoft.com/visualstudio/code-quality/ca5377): Use Container Level Access Policy - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5377](https://docs.microsoft.com/visualstudio/code-quality/ca5377): Use Container Level Access Policy No access policy identifier is specified, making tokens non-revocable. -## [CA5378](https://docs.microsoft.com/visualstudio/code-quality/ca5378): Do not disable ServicePointManagerSecurityProtocols - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5378](https://docs.microsoft.com/visualstudio/code-quality/ca5378): Do not disable ServicePointManagerSecurityProtocols Do not set Switch.System.ServiceModel.DisableUsingServicePointManagerSecurityProtocols to true. Setting this switch limits Windows Communication Framework (WCF) to using Transport Layer Security (TLS) 1.0, which is insecure and obsolete. -## [CA5379](https://docs.microsoft.com/visualstudio/code-quality/ca5379): Do Not Use Weak Key Derivation Function Algorithm - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5379](https://docs.microsoft.com/visualstudio/code-quality/ca5379): Do Not Use Weak Key Derivation Function Algorithm Some implementations of the Rfc2898DeriveBytes class allow for a hash algorithm to be specified in a constructor parameter or overwritten in the HashAlgorithm property. If a hash algorithm is specified, then it should be SHA-256 or higher. -## [CA5380](https://docs.microsoft.com/visualstudio/code-quality/ca5380): Do Not Add Certificates To Root Store - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5380](https://docs.microsoft.com/visualstudio/code-quality/ca5380): Do Not Add Certificates To Root Store By default, the Trusted Root Certification Authorities certificate store is configured with a set of public CAs that has met the requirements of the Microsoft Root Certificate Program. Since all trusted root CAs can issue certificates for any domain, an attacker can pick a weak or coercible CA that you install by yourself to target for an attack – and a single vulnerable, malicious or coercible CA undermines the security of the entire system. To make matters worse, these attacks can go unnoticed quite easily. -## [CA5381](https://docs.microsoft.com/visualstudio/code-quality/ca5381): Ensure Certificates Are Not Added To Root Store - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5381](https://docs.microsoft.com/visualstudio/code-quality/ca5381): Ensure Certificates Are Not Added To Root Store By default, the Trusted Root Certification Authorities certificate store is configured with a set of public CAs that has met the requirements of the Microsoft Root Certificate Program. Since all trusted root CAs can issue certificates for any domain, an attacker can pick a weak or coercible CA that you install by yourself to target for an attack – and a single vulnerable, malicious or coercible CA undermines the security of the entire system. To make matters worse, these attacks can go unnoticed quite easily. -## [CA5382](https://docs.microsoft.com/visualstudio/code-quality/ca5382): Use Secure Cookies In ASP.Net Core - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5382](https://docs.microsoft.com/visualstudio/code-quality/ca5382): Use Secure Cookies In ASP.Net Core Applications available over HTTPS must use secure cookies. -## [CA5383](https://docs.microsoft.com/visualstudio/code-quality/ca5383): Ensure Use Secure Cookies In ASP.Net Core - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5383](https://docs.microsoft.com/visualstudio/code-quality/ca5383): Ensure Use Secure Cookies In ASP.Net Core Applications available over HTTPS must use secure cookies. -## [CA5384](https://docs.microsoft.com/visualstudio/code-quality/ca5384): Do Not Use Digital Signature Algorithm (DSA) - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5384](https://docs.microsoft.com/visualstudio/code-quality/ca5384): Do Not Use Digital Signature Algorithm (DSA) DSA is too weak to use. -## [CA5385](https://docs.microsoft.com/visualstudio/code-quality/ca5385): Use Rivest–Shamir–Adleman (RSA) Algorithm With Sufficient Key Size - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5385](https://docs.microsoft.com/visualstudio/code-quality/ca5385): Use Rivest–Shamir–Adleman (RSA) Algorithm With Sufficient Key Size Encryption algorithms are vulnerable to brute force attacks when too small a key size is used. -## [CA5386](https://docs.microsoft.com/visualstudio/code-quality/ca5386): Avoid hardcoding SecurityProtocolType value - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5386](https://docs.microsoft.com/visualstudio/code-quality/ca5386): Avoid hardcoding SecurityProtocolType value Avoid hardcoding SecurityProtocolType {0}, and instead use SecurityProtocolType.SystemDefault to allow the operating system to choose the best Transport Layer Security protocol to use. -## [CA5387](https://docs.microsoft.com/visualstudio/code-quality/ca5387): Do Not Use Weak Key Derivation Function With Insufficient Iteration Count - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5387](https://docs.microsoft.com/visualstudio/code-quality/ca5387): Do Not Use Weak Key Derivation Function With Insufficient Iteration Count When deriving cryptographic keys from user-provided inputs such as password, use sufficient iteration count (at least 100k). -## [CA5388](https://docs.microsoft.com/visualstudio/code-quality/ca5388): Ensure Sufficient Iteration Count When Using Weak Key Derivation Function - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5388](https://docs.microsoft.com/visualstudio/code-quality/ca5388): Ensure Sufficient Iteration Count When Using Weak Key Derivation Function When deriving cryptographic keys from user-provided inputs such as password, use sufficient iteration count (at least 100k). -## [CA5389](https://docs.microsoft.com/visualstudio/code-quality/ca5389): Do Not Add Archive Item's Path To The Target File System Path - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5389](https://docs.microsoft.com/visualstudio/code-quality/ca5389): Do Not Add Archive Item's Path To The Target File System Path When extracting files from an archive and using the archive item's path, check if the path is safe. Archive path can be relative and can lead to file system access outside of the expected file system target path, leading to malicious config changes and remote code execution via lay-and-wait technique. -## [CA5390](https://docs.microsoft.com/visualstudio/code-quality/ca5390): Do not hard-code encryption key - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5390](https://docs.microsoft.com/visualstudio/code-quality/ca5390): Do not hard-code encryption key SymmetricAlgorithm's .Key property, or a method's rgbKey parameter, should never be a hard-coded value. -## [CA5391](https://docs.microsoft.com/visualstudio/code-quality/ca5391): Use antiforgery tokens in ASP.NET Core MVC controllers - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5391](https://docs.microsoft.com/visualstudio/code-quality/ca5391): Use antiforgery tokens in ASP.NET Core MVC controllers Handling a POST, PUT, PATCH, or DELETE request without validating an antiforgery token may be vulnerable to cross-site request forgery attacks. A cross-site request forgery attack can send malicious requests from an authenticated user to your ASP.NET Core MVC controller. -## [CA5392](https://docs.microsoft.com/visualstudio/code-quality/ca5392): Use DefaultDllImportSearchPaths attribute for P/Invokes - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5392](https://docs.microsoft.com/visualstudio/code-quality/ca5392): Use DefaultDllImportSearchPaths attribute for P/Invokes By default, P/Invokes using DllImportAttribute probe a number of directories, including the current working directory for the library to load. This can be a security issue for certain applications, leading to DLL hijacking. -## [CA5393](https://docs.microsoft.com/visualstudio/code-quality/ca5393): Do not use unsafe DllImportSearchPath value - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5393](https://docs.microsoft.com/visualstudio/code-quality/ca5393): Do not use unsafe DllImportSearchPath value There could be a malicious DLL in the default DLL search directories. Or, depending on where your application is run from, there could be a malicious DLL in the application's directory. Use a DllImportSearchPath value that specifies an explicit search path instead. The DllImportSearchPath flags that this rule looks for can be configured in .editorconfig. -## [CA5394](https://docs.microsoft.com/visualstudio/code-quality/ca5394): Do not use insecure randomness - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5394](https://docs.microsoft.com/visualstudio/code-quality/ca5394): Do not use insecure randomness Using a cryptographically weak pseudo-random number generator may allow an attacker to predict what security-sensitive value will be generated. Use a cryptographically strong random number generator if an unpredictable value is required, or ensure that weak pseudo-random numbers aren't used in a security-sensitive manner. -## [CA5395](https://docs.microsoft.com/visualstudio/code-quality/ca5395): Miss HttpVerb attribute for action methods - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5395](https://docs.microsoft.com/visualstudio/code-quality/ca5395): Miss HttpVerb attribute for action methods All the methods that create, edit, delete, or otherwise modify data do so in the [HttpPost] overload of the method, which needs to be protected with the anti forgery attribute from request forgery. Performing a GET operation should be a safe operation that has no side effects and doesn't modify your persisted data. -## [CA5396](https://docs.microsoft.com/visualstudio/code-quality/ca5396): Set HttpOnly to true for HttpCookie - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5396](https://docs.microsoft.com/visualstudio/code-quality/ca5396): Set HttpOnly to true for HttpCookie As a defense in depth measure, ensure security sensitive HTTP cookies are marked as HttpOnly. This indicates web browsers should disallow scripts from accessing the cookies. Injected malicious scripts are a common way of stealing cookies. -## [CA5397](https://docs.microsoft.com/visualstudio/code-quality/ca5397): Do not use deprecated SslProtocols values - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5397](https://docs.microsoft.com/visualstudio/code-quality/ca5397): Do not use deprecated SslProtocols values Older protocol versions of Transport Layer Security (TLS) are less secure than TLS 1.2 and TLS 1.3, and are more likely to have new vulnerabilities. Avoid older protocol versions to minimize risk. -## [CA5398](https://docs.microsoft.com/visualstudio/code-quality/ca5398): Avoid hardcoded SslProtocols values - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5398](https://docs.microsoft.com/visualstudio/code-quality/ca5398): Avoid hardcoded SslProtocols values Current Transport Layer Security protocol versions may become deprecated if vulnerabilities are found. Avoid hardcoding SslProtocols values to keep your application secure. Use 'None' to let the Operating System choose a version. -## [CA5399](https://docs.microsoft.com/visualstudio/code-quality/ca5399): HttpClients should enable certificate revocation list checks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5399](https://docs.microsoft.com/visualstudio/code-quality/ca5399): HttpClients should enable certificate revocation list checks Using HttpClient without providing a platform specific handler (WinHttpHandler or CurlHandler or HttpClientHandler) where the CheckCertificateRevocationList property is set to true, will allow revoked certificates to be accepted by the HttpClient as valid. -## [CA5400](https://docs.microsoft.com/visualstudio/code-quality/ca5400): Ensure HttpClient certificate revocation list check is not disabled - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5400](https://docs.microsoft.com/visualstudio/code-quality/ca5400): Ensure HttpClient certificate revocation list check is not disabled Using HttpClient without providing a platform specific handler (WinHttpHandler or CurlHandler or HttpClientHandler) where the CheckCertificateRevocationList property is set to true, will allow revoked certificates to be accepted by the HttpClient as valid. -## [CA5401](https://docs.microsoft.com/visualstudio/code-quality/ca5401): Do not use CreateEncryptor with non-default IV - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5401](https://docs.microsoft.com/visualstudio/code-quality/ca5401): Do not use CreateEncryptor with non-default IV Symmetric encryption should always use a non-repeatable initialization vector to prevent dictionary attacks. -## [CA5402](https://docs.microsoft.com/visualstudio/code-quality/ca5402): Use CreateEncryptor with the default IV - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5402](https://docs.microsoft.com/visualstudio/code-quality/ca5402): Use CreateEncryptor with the default IV Symmetric encryption should always use a non-repeatable initialization vector to prevent dictionary attacks. -## [CA5403](https://docs.microsoft.com/visualstudio/code-quality/ca5403): Do not hard-code certificate - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5403](https://docs.microsoft.com/visualstudio/code-quality/ca5403): Do not hard-code certificate Hard-coded certificates in source code are vulnerable to being exploited. -## CA9999: Analyzer version mismatch - |Item|Value| |-|-| -|Category|Reliability| -|Enabled|True| +|Category|Security| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## CA9999: Analyzer version mismatch Analyzers in this package require a certain minimum version of Microsoft.CodeAnalysis to execute correctly. Refer to https://docs.microsoft.com/visualstudio/code-quality/install-fxcop-analyzers#fxcopanalyzers-package-versions to install the correct analyzer version. -## [IL3000](https://docs.microsoft.com/visualstudio/code-quality/il3000): Avoid using accessing Assembly file path when publishing as a single-file - |Item|Value| |-|-| -|Category|Publish| +|Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [IL3000](https://docs.microsoft.com/visualstudio/code-quality/il3000): Avoid using accessing Assembly file path when publishing as a single-file '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. -## [IL3001](https://docs.microsoft.com/visualstudio/code-quality/il3001): Avoid using accessing Assembly file path when publishing as a single-file - |Item|Value| |-|-| |Category|Publish| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [IL3001](https://docs.microsoft.com/visualstudio/code-quality/il3001): Avoid using accessing Assembly file path when publishing as a single-file '{0}' will throw for assemblies embedded in a single-file app +|Item|Value| +|-|-| +|Category|Publish| +|Enabled|True| +|Severity|Warning| +|CodeFix|False| +--- diff --git a/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.sarif b/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.sarif index ca1315922a..28ef180c7a 100644 --- a/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.sarif +++ b/src/Microsoft.CodeAnalysis.FxCopAnalyzers/Microsoft.CodeAnalysis.FxCopAnalyzers.sarif @@ -2266,13 +2266,13 @@ }, "CA1307": { "id": "CA1307", - "shortDescription": "Specify StringComparison", - "fullDescription": "A string comparison operation uses a method overload that does not set a StringComparison parameter. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'.", + "shortDescription": "Specify StringComparison for clarity", + "fullDescription": "A string comparison operation uses a method overload that does not set a StringComparison parameter. It is recommended to use the overload with StringComparison parameter for clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'.", "defaultLevel": "warning", "helpUri": "https://docs.microsoft.com/visualstudio/code-quality/ca1307", "properties": { "category": "Globalization", - "isEnabledByDefault": true, + "isEnabledByDefault": false, "typeName": "SpecifyStringComparisonAnalyzer", "languages": [ "C#", @@ -2304,6 +2304,25 @@ ] } }, + "CA1310": { + "id": "CA1310", + "shortDescription": "Specify StringComparison for correctness", + "fullDescription": "A string comparison operation uses a method overload that does not set a StringComparison parameter, hence its behavior could vary based on the current user's locale settings. It is strongly recommended to use the overload with StringComparison parameter for correctness and clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'.", + "defaultLevel": "warning", + "helpUri": "https://docs.microsoft.com/visualstudio/code-quality/ca1310", + "properties": { + "category": "Globalization", + "isEnabledByDefault": true, + "typeName": "SpecifyStringComparisonAnalyzer", + "languages": [ + "C#", + "Visual Basic" + ], + "tags": [ + "Telemetry" + ] + } + }, "CA1401": { "id": "CA1401", "shortDescription": "P/Invokes should not be visible", @@ -2324,6 +2343,25 @@ ] } }, + "CA1416": { + "id": "CA1416", + "shortDescription": "Validate platform compatibility", + "fullDescription": "Using platform dependent API on a component makes the code no longer work across all platforms.", + "defaultLevel": "warning", + "helpUri": "https://docs.microsoft.com/visualstudio/code-quality/ca1416", + "properties": { + "category": "Interoperability", + "isEnabledByDefault": true, + "typeName": "PlatformCompatabilityAnalyzer", + "languages": [ + "C#", + "Visual Basic" + ], + "tags": [ + "Telemetry" + ] + } + }, "CA1417": { "id": "CA1417", "shortDescription": "Do not use 'OutAttribute' on string parameters for P/Invokes", @@ -4866,7 +4904,7 @@ "rules": { "CA1309": { "id": "CA1309", - "shortDescription": "Use ordinal stringcomparison", + "shortDescription": "Use ordinal string comparison", "fullDescription": "A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable.", "defaultLevel": "warning", "helpUri": "https://docs.microsoft.com/visualstudio/code-quality/ca1309", @@ -4949,7 +4987,7 @@ "rules": { "CA1309": { "id": "CA1309", - "shortDescription": "Use ordinal stringcomparison", + "shortDescription": "Use ordinal string comparison", "fullDescription": "A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable.", "defaultLevel": "warning", "helpUri": "https://docs.microsoft.com/visualstudio/code-quality/ca1309", diff --git a/src/Microsoft.CodeAnalysis.FxCopAnalyzers/RulesMissingDocumentation.md b/src/Microsoft.CodeAnalysis.FxCopAnalyzers/RulesMissingDocumentation.md index 7130f8295c..7c4d8fbba3 100644 --- a/src/Microsoft.CodeAnalysis.FxCopAnalyzers/RulesMissingDocumentation.md +++ b/src/Microsoft.CodeAnalysis.FxCopAnalyzers/RulesMissingDocumentation.md @@ -1,17 +1,6 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| -CA1830 | https://docs.microsoft.com/visualstudio/code-quality/ca1830 | Prefer strongly-typed Append and Insert method overloads on StringBuilder. | -CA1831 | https://docs.microsoft.com/visualstudio/code-quality/ca1831 | Use AsSpan or AsMemory instead of Range-based indexers when appropriate | -CA1832 | https://docs.microsoft.com/visualstudio/code-quality/ca1832 | Use AsSpan or AsMemory instead of Range-based indexers when appropriate | -CA1833 | https://docs.microsoft.com/visualstudio/code-quality/ca1833 | Use AsSpan or AsMemory instead of Range-based indexers when appropriate | -CA1834 | https://docs.microsoft.com/visualstudio/code-quality/ca1834 | Consider using 'StringBuilder.Append(char)' when applicable. | -CA1835 | https://docs.microsoft.com/visualstudio/code-quality/ca1835 | Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'. | -CA1836 | https://docs.microsoft.com/visualstudio/code-quality/ca1836 | Prefer IsEmpty over Count | -CA2008 | https://docs.microsoft.com/visualstudio/code-quality/ca2008 | Do not create tasks without passing a TaskScheduler | -CA2012 | https://docs.microsoft.com/visualstudio/code-quality/ca2012 | Use ValueTasks correctly | -CA2014 | https://docs.microsoft.com/visualstudio/code-quality/ca2014 | Do not use stackalloc in loops. | -CA2247 | https://docs.microsoft.com/visualstudio/code-quality/ca2247 | Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum. | -CA2249 | https://docs.microsoft.com/visualstudio/code-quality/ca2249 | Consider using 'string.Contains' instead of 'string.IndexOf' | +CA1416 | https://docs.microsoft.com/visualstudio/code-quality/ca1416 | Validate platform compatibility | CA9999 | | Analyzer version mismatch | diff --git a/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/Microsoft.CodeAnalysis.VersionCheckAnalyzer.md b/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/Microsoft.CodeAnalysis.VersionCheckAnalyzer.md index 8b99036ea9..caa73d45ee 100644 --- a/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/Microsoft.CodeAnalysis.VersionCheckAnalyzer.md +++ b/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/Microsoft.CodeAnalysis.VersionCheckAnalyzer.md @@ -2,14 +2,12 @@ ## CA9999: Analyzer version mismatch +Analyzers in this package require a certain minimum version of Microsoft.CodeAnalysis to execute correctly. Refer to https://docs.microsoft.com/visualstudio/code-quality/install-fxcop-analyzers#fxcopanalyzers-package-versions to install the correct analyzer version. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Analyzers in this package require a certain minimum version of Microsoft.CodeAnalysis to execute correctly. Refer to https://docs.microsoft.com/visualstudio/code-quality/install-fxcop-analyzers#fxcopanalyzers-package-versions to install the correct analyzer version. - +--- diff --git a/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/RulesMissingDocumentation.md b/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/RulesMissingDocumentation.md index 40e2895e36..1e4217990d 100644 --- a/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/RulesMissingDocumentation.md +++ b/src/Microsoft.CodeAnalysis.VersionCheckAnalyzer/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/Microsoft.CodeQuality.Analyzers/Microsoft.CodeQuality.Analyzers.md b/src/Microsoft.CodeQuality.Analyzers/Microsoft.CodeQuality.Analyzers.md index e214247c54..e476d1cef7 100644 --- a/src/Microsoft.CodeQuality.Analyzers/Microsoft.CodeQuality.Analyzers.md +++ b/src/Microsoft.CodeQuality.Analyzers/Microsoft.CodeQuality.Analyzers.md @@ -2,564 +2,511 @@ ## [CA1000](https://docs.microsoft.com/visualstudio/code-quality/ca1000): Do not declare static members on generic types +When a static member of a generic type is called, the type argument must be specified for the type. When a generic instance member that does not support inference is called, the type argument must be specified for the member. In these two cases, the syntax for specifying the type argument is different and easily confused. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -When a static member of a generic type is called, the type argument must be specified for the type. When a generic instance member that does not support inference is called, the type argument must be specified for the member. In these two cases, the syntax for specifying the type argument is different and easily confused. +--- ## [CA1001](https://docs.microsoft.com/visualstudio/code-quality/ca1001): Types that own disposable fields should be disposable +A class declares and implements an instance field that is a System.IDisposable type, and the class does not implement IDisposable. A class that declares an IDisposable field indirectly owns an unmanaged resource and should implement the IDisposable interface. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -A class declares and implements an instance field that is a System.IDisposable type, and the class does not implement IDisposable. A class that declares an IDisposable field indirectly owns an unmanaged resource and should implement the IDisposable interface. +--- ## [CA1002](https://docs.microsoft.com/visualstudio/code-quality/ca1002): Do not expose generic lists +System.Collections.Generic.List\ is a generic collection that's designed for performance and not inheritance. List\ does not contain virtual members that make it easier to change the behavior of an inherited class. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -System.Collections.Generic.List is a generic collection that's designed for performance and not inheritance. List does not contain virtual members that make it easier to change the behavior of an inherited class. +--- ## [CA1003](https://docs.microsoft.com/visualstudio/code-quality/ca1003): Use generic event handler instances +A type contains an event that declares an EventHandler delegate that returns void, whose signature contains two parameters (the first an object and the second a type that is assignable to EventArgs), and the containing assembly targets Microsoft .NET Framework?2.0. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A type contains an event that declares an EventHandler delegate that returns void, whose signature contains two parameters (the first an object and the second a type that is assignable to EventArgs), and the containing assembly targets Microsoft .NET Framework?2.0. +--- ## [CA1005](https://docs.microsoft.com/visualstudio/code-quality/ca1005): Avoid excessive parameters on generic types +The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. +--- ## [CA1008](https://docs.microsoft.com/visualstudio/code-quality/ca1008): Enums should have zero value +The default value of an uninitialized enumeration, just as other value types, is zero. A nonflags-attributed enumeration should define a member by using the value of zero so that the default value is a valid value of the enumeration. If an enumeration that has the FlagsAttribute attribute applied defines a zero-valued member, its name should be ""None"" to indicate that no values have been set in the enumeration. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -The default value of an uninitialized enumeration, just as other value types, is zero. A nonflags-attributed enumeration should define a member by using the value of zero so that the default value is a valid value of the enumeration. If an enumeration that has the FlagsAttribute attribute applied defines a zero-valued member, its name should be ""None"" to indicate that no values have been set in the enumeration. +--- ## [CA1010](https://docs.microsoft.com/visualstudio/code-quality/ca1010): Generic interface should also be implemented +To broaden the usability of a type, implement one of the generic interfaces. This is especially true for collections as they can then be used to populate generic collection types. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -To broaden the usability of a type, implement one of the generic interfaces. This is especially true for collections as they can then be used to populate generic collection types. +--- ## [CA1012](https://docs.microsoft.com/visualstudio/code-quality/ca1012): Abstract types should not have public constructors +Constructors on abstract types can be called only by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type that has a public constructor is incorrectly designed. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Constructors on abstract types can be called only by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type that has a public constructor is incorrectly designed. +--- ## [CA1014](https://docs.microsoft.com/visualstudio/code-quality/ca1014): Mark assemblies with CLSCompliant +The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages. Good design dictates that all assemblies explicitly indicate CLS compliance by using CLSCompliantAttribute . If this attribute is not present on an assembly, the assembly is not compliant. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages. Good design dictates that all assemblies explicitly indicate CLS compliance by using CLSCompliantAttribute . If this attribute is not present on an assembly, the assembly is not compliant. +--- ## [CA1016](https://docs.microsoft.com/visualstudio/code-quality/ca1016): Mark assemblies with assembly version +The .NET Framework uses the version number to uniquely identify an assembly, and to bind to types in strongly named assemblies. The version number is used together with version and publisher policy. By default, applications run only with the assembly version with which they were built. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -The .NET Framework uses the version number to uniquely identify an assembly, and to bind to types in strongly named assemblies. The version number is used together with version and publisher policy. By default, applications run only with the assembly version with which they were built. +--- ## [CA1017](https://docs.microsoft.com/visualstudio/code-quality/ca1017): Mark assemblies with ComVisible +ComVisibleAttribute determines how COM clients access managed code. Good design dictates that assemblies explicitly indicate COM visibility. COM visibility can be set for the whole assembly and then overridden for individual types and type members. If this attribute is not present, the contents of the assembly are visible to COM clients. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -ComVisibleAttribute determines how COM clients access managed code. Good design dictates that assemblies explicitly indicate COM visibility. COM visibility can be set for the whole assembly and then overridden for individual types and type members. If this attribute is not present, the contents of the assembly are visible to COM clients. +--- ## [CA1018](https://docs.microsoft.com/visualstudio/code-quality/ca1018): Mark attributes with AttributeUsageAttribute +Specify AttributeUsage on {0} + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Specify AttributeUsage on {0} +--- ## [CA1019](https://docs.microsoft.com/visualstudio/code-quality/ca1019): Define accessors for attribute arguments -|Item|Value| -|-|-| -|Category|Design| -|Enabled|False| -|Severity|Warning| -|CodeFix|True| - -### Rule description - Remove the property setter from {0} or reduce its accessibility because it corresponds to positional argument {1} -## [CA1021](https://docs.microsoft.com/visualstudio/code-quality/ca1021): Avoid out parameters - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1021](https://docs.microsoft.com/visualstudio/code-quality/ca1021): Avoid out parameters Passing types by reference (using 'out' or 'ref') requires experience with pointers, understanding how value types and reference types differ, and handling methods with multiple return values. Also, the difference between 'out' and 'ref' parameters is not widely understood. -## [CA1024](https://docs.microsoft.com/visualstudio/code-quality/ca1024): Use properties where appropriate - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1024](https://docs.microsoft.com/visualstudio/code-quality/ca1024): Use properties where appropriate A public or protected method has a name that starts with ""Get"", takes no parameters, and returns a value that is not an array. The method might be a good candidate to become a property. -## [CA1027](https://docs.microsoft.com/visualstudio/code-quality/ca1027): Mark enums with FlagsAttribute - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1027](https://docs.microsoft.com/visualstudio/code-quality/ca1027): Mark enums with FlagsAttribute An enumeration is a value type that defines a set of related named constants. Apply FlagsAttribute to an enumeration when its named constants can be meaningfully combined. -## [CA1028](https://docs.microsoft.com/visualstudio/code-quality/ca1028): Enum Storage should be Int32 - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1028](https://docs.microsoft.com/visualstudio/code-quality/ca1028): Enum Storage should be Int32 An enumeration is a value type that defines a set of related named constants. By default, the System.Int32 data type is used to store the constant value. Although you can change this underlying type, it is not required or recommended for most scenarios. -## [CA1030](https://docs.microsoft.com/visualstudio/code-quality/ca1030): Use events where appropriate - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1030](https://docs.microsoft.com/visualstudio/code-quality/ca1030): Use events where appropriate This rule detects methods that have names that ordinarily would be used for events. If a method is called in response to a clearly defined state change, the method should be invoked by an event handler. Objects that call the method should raise events instead of calling the method directly. -## [CA1031](https://docs.microsoft.com/visualstudio/code-quality/ca1031): Do not catch general exception types - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1031](https://docs.microsoft.com/visualstudio/code-quality/ca1031): Do not catch general exception types A general exception such as System.Exception or System.SystemException or a disallowed exception type is caught in a catch statement, or a general catch clause is used. General and disallowed exceptions should not be caught. -## [CA1032](https://docs.microsoft.com/visualstudio/code-quality/ca1032): Implement standard exception constructors - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1032](https://docs.microsoft.com/visualstudio/code-quality/ca1032): Implement standard exception constructors Failure to provide the full set of constructors can make it difficult to correctly handle exceptions. -## [CA1033](https://docs.microsoft.com/visualstudio/code-quality/ca1033): Interface methods should be callable by child types - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1033](https://docs.microsoft.com/visualstudio/code-quality/ca1033): Interface methods should be callable by child types An unsealed externally visible type provides an explicit method implementation of a public interface and does not provide an alternative externally visible method that has the same name. -## [CA1034](https://docs.microsoft.com/visualstudio/code-quality/ca1034): Nested types should not be visible - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1034](https://docs.microsoft.com/visualstudio/code-quality/ca1034): Nested types should not be visible A nested type is a type that is declared in the scope of another type. Nested types are useful to encapsulate private implementation details of the containing type. Used for this purpose, nested types should not be externally visible. -## [CA1036](https://docs.microsoft.com/visualstudio/code-quality/ca1036): Override methods on comparable types - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1036](https://docs.microsoft.com/visualstudio/code-quality/ca1036): Override methods on comparable types A public or protected type implements the System.IComparable interface. It does not override Object.Equals nor does it overload the language-specific operator for equality, inequality, less than, less than or equal, greater than or greater than or equal. -## [CA1040](https://docs.microsoft.com/visualstudio/code-quality/ca1040): Avoid empty interfaces - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1040](https://docs.microsoft.com/visualstudio/code-quality/ca1040): Avoid empty interfaces Interfaces define members that provide a behavior or usage contract. The functionality that is described by the interface can be adopted by any type, regardless of where the type appears in the inheritance hierarchy. A type implements an interface by providing implementations for the members of the interface. An empty interface does not define any members; therefore, it does not define a contract that can be implemented. -## [CA1041](https://docs.microsoft.com/visualstudio/code-quality/ca1041): Provide ObsoleteAttribute message - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1041](https://docs.microsoft.com/visualstudio/code-quality/ca1041): Provide ObsoleteAttribute message A type or member is marked by using a System.ObsoleteAttribute attribute that does not have its ObsoleteAttribute.Message property specified. When a type or member that is marked by using ObsoleteAttribute is compiled, the Message property of the attribute is displayed. This gives the user information about the obsolete type or member. -## [CA1043](https://docs.microsoft.com/visualstudio/code-quality/ca1043): Use Integral Or String Argument For Indexers - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1043](https://docs.microsoft.com/visualstudio/code-quality/ca1043): Use Integral Or String Argument For Indexers Indexers, that is, indexed properties, should use integer or string types for the index. These types are typically used for indexing data structures and increase the usability of the library. Use of the Object type should be restricted to those cases where the specific integer or string type cannot be specified at design time. If the design requires other types for the index, reconsider whether the type represents a logical data store. If it does not represent a logical data store, use a method. -## [CA1044](https://docs.microsoft.com/visualstudio/code-quality/ca1044): Properties should not be write only - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1044](https://docs.microsoft.com/visualstudio/code-quality/ca1044): Properties should not be write only Although it is acceptable and often necessary to have a read-only property, the design guidelines prohibit the use of write-only properties. This is because letting a user set a value, and then preventing the user from viewing that value, does not provide any security. Also, without read access, the state of shared objects cannot be viewed, which limits their usefulness. -## [CA1045](https://docs.microsoft.com/visualstudio/code-quality/ca1045): Do not pass types by reference - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1045](https://docs.microsoft.com/visualstudio/code-quality/ca1045): Do not pass types by reference Passing types by reference (using out or ref) requires experience with pointers, understanding how value types and reference types differ, and handling methods that have multiple return values. Also, the difference between out and ref parameters is not widely understood. -## [CA1046](https://docs.microsoft.com/visualstudio/code-quality/ca1046): Do not overload equality operator on reference types - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1046](https://docs.microsoft.com/visualstudio/code-quality/ca1046): Do not overload equality operator on reference types For reference types, the default implementation of the equality operator is almost always correct. By default, two references are equal only if they point to the same object. If the operator is providing meaningful value equality, the type should implement the generic 'System.IEquatable' interface. -## [CA1047](https://docs.microsoft.com/visualstudio/code-quality/ca1047): Do not declare protected member in sealed type - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1047](https://docs.microsoft.com/visualstudio/code-quality/ca1047): Do not declare protected member in sealed type Types declare protected members so that inheriting types can access or override the member. By definition, you cannot inherit from a sealed type, which means that protected methods on sealed types cannot be called. -## [CA1050](https://docs.microsoft.com/visualstudio/code-quality/ca1050): Declare types in namespaces - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1050](https://docs.microsoft.com/visualstudio/code-quality/ca1050): Declare types in namespaces Types are declared in namespaces to prevent name collisions and as a way to organize related types in an object hierarchy. -## [CA1051](https://docs.microsoft.com/visualstudio/code-quality/ca1051): Do not declare visible instance fields - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1051](https://docs.microsoft.com/visualstudio/code-quality/ca1051): Do not declare visible instance fields The primary use of a field should be as an implementation detail. Fields should be private or internal and should be exposed by using properties. -## [CA1052](https://docs.microsoft.com/visualstudio/code-quality/ca1052): Static holder types should be Static or NotInheritable - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1052](https://docs.microsoft.com/visualstudio/code-quality/ca1052): Static holder types should be Static or NotInheritable Type '{0}' is a static holder type but is neither static nor NotInheritable -## [CA1054](https://docs.microsoft.com/visualstudio/code-quality/ca1054): URI-like parameters should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1054](https://docs.microsoft.com/visualstudio/code-quality/ca1054): URI-like parameters should not be strings This rule assumes that the parameter represents a Uniform Resource Identifier (URI). A string representation or a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. 'System.Uri' class provides these services in a safe and secure manner. -## [CA1055](https://docs.microsoft.com/visualstudio/code-quality/ca1055): URI-like return values should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1055](https://docs.microsoft.com/visualstudio/code-quality/ca1055): URI-like return values should not be strings This rule assumes that the method returns a URI. A string representation of a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. The System.Uri class provides these services in a safe and secure manner. -## [CA1056](https://docs.microsoft.com/visualstudio/code-quality/ca1056): URI-like properties should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1056](https://docs.microsoft.com/visualstudio/code-quality/ca1056): URI-like properties should not be strings This rule assumes that the property represents a Uniform Resource Identifier (URI). A string representation of a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. The System.Uri class provides these services in a safe and secure manner. -## [CA1060](https://docs.microsoft.com/visualstudio/code-quality/ca1060): Move pinvokes to native methods class - |Item|Value| |-|-| |Category|Design| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1060](https://docs.microsoft.com/visualstudio/code-quality/ca1060): Move pinvokes to native methods class Platform Invocation methods, such as those that are marked by using the System.Runtime.InteropServices.DllImportAttribute attribute, or methods that are defined by using the Declare keyword in Visual Basic, access unmanaged code. These methods should be of the NativeMethods, SafeNativeMethods, or UnsafeNativeMethods class. -## [CA1061](https://docs.microsoft.com/visualstudio/code-quality/ca1061): Do not hide base class methods - |Item|Value| |-|-| |Category|Design| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1061](https://docs.microsoft.com/visualstudio/code-quality/ca1061): Do not hide base class methods A method in a base type is hidden by an identically named method in a derived type when the parameter signature of the derived method differs only by types that are more weakly derived than the corresponding types in the parameter signature of the base method. -## [CA1062](https://docs.microsoft.com/visualstudio/code-quality/ca1062): Validate arguments of public methods - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1062](https://docs.microsoft.com/visualstudio/code-quality/ca1062): Validate arguments of public methods An externally visible method dereferences one of its reference arguments without verifying whether that argument is null (Nothing in Visual Basic). All reference arguments that are passed to externally visible methods should be checked against null. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. If the method is designed to be called only by known assemblies, you should make the method internal. -## [CA1063](https://docs.microsoft.com/visualstudio/code-quality/ca1063): Implement IDisposable Correctly - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1063](https://docs.microsoft.com/visualstudio/code-quality/ca1063): Implement IDisposable Correctly All IDisposable types should implement the Dispose pattern correctly. -## [CA1064](https://docs.microsoft.com/visualstudio/code-quality/ca1064): Exceptions should be public - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1064](https://docs.microsoft.com/visualstudio/code-quality/ca1064): Exceptions should be public An internal exception is visible only inside its own internal scope. After the exception falls outside the internal scope, only the base exception can be used to catch the exception. If the internal exception is inherited from T:System.Exception, T:System.SystemException, or T:System.ApplicationException, the external code will not have sufficient information to know what to do with the exception. -## [CA1065](https://docs.microsoft.com/visualstudio/code-quality/ca1065): Do not raise exceptions in unexpected locations - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1065](https://docs.microsoft.com/visualstudio/code-quality/ca1065): Do not raise exceptions in unexpected locations A method that is not expected to throw exceptions throws an exception. -## [CA1066](https://docs.microsoft.com/visualstudio/code-quality/ca1066): Implement IEquatable when overriding Object.Equals - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|True| - -### Rule description +|CodeFix|False| +--- -When a type T overrides Object.Equals(object), the implementation must cast the object argument to the correct type T before performing the comparison. If the type implements IEquatable, and therefore offers the method T.Equals(T), and if the argument is known at compile time to be of type T, then the compiler can call IEquatable.Equals(T) instead of Object.Equals(object), and no cast is necessary, improving performance. +## [CA1066](https://docs.microsoft.com/visualstudio/code-quality/ca1066): Implement IEquatable when overriding Object.Equals -## [CA1067](https://docs.microsoft.com/visualstudio/code-quality/ca1067): Override Object.Equals(object) when implementing IEquatable +When a type T overrides Object.Equals(object), the implementation must cast the object argument to the correct type T before performing the comparison. If the type implements IEquatable\, and therefore offers the method T.Equals(T), and if the argument is known at compile time to be of type T, then the compiler can call IEquatable\.Equals(T) instead of Object.Equals(object), and no cast is necessary, improving performance. |Item|Value| |-|-| @@ -567,736 +514,688 @@ When a type T overrides Object.Equals(object), the implementation must cast the |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1067](https://docs.microsoft.com/visualstudio/code-quality/ca1067): Override Object.Equals(object) when implementing IEquatable\ -When a type T implements the interface IEquatable, it suggests to a user who sees a call to the Equals method in source code that an instance of the type can be equated with an instance of any other type. The user might be confused if their attempt to equate the type with an instance of another type fails to compile. This violates the "principle of least surprise". - -## [CA1068](https://docs.microsoft.com/visualstudio/code-quality/ca1068): CancellationToken parameters must come last +When a type T implements the interface IEquatable\, it suggests to a user who sees a call to the Equals method in source code that an instance of the type can be equated with an instance of any other type. The user might be confused if their attempt to equate the type with an instance of another type fails to compile. This violates the "principle of least surprise". |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1068](https://docs.microsoft.com/visualstudio/code-quality/ca1068): CancellationToken parameters must come last Method '{0}' should take CancellationToken as the last parameter -## [CA1069](https://docs.microsoft.com/visualstudio/code-quality/ca1069): Enums values should not be duplicated - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1069](https://docs.microsoft.com/visualstudio/code-quality/ca1069): Enums values should not be duplicated The field reference '{0}' is duplicated in this bitwise initialization -## [CA1070](https://docs.microsoft.com/visualstudio/code-quality/ca1070): Do not declare event fields as virtual - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1070](https://docs.microsoft.com/visualstudio/code-quality/ca1070): Do not declare event fields as virtual Do not declare virtual events in a base class. Overridden events in a derived class have undefined behavior. The C# compiler does not handle this correctly and it is unpredictable whether a subscriber to the derived event will actually be subscribing to the base class event. -## [CA1200](https://docs.microsoft.com/visualstudio/code-quality/ca1200): Avoid using cref tags with a prefix - |Item|Value| |-|-| -|Category|Documentation| +|Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1200](https://docs.microsoft.com/visualstudio/code-quality/ca1200): Avoid using cref tags with a prefix Use of cref tags with prefixes should be avoided, since it prevents the compiler from verifying references and the IDE from updating references during refactorings. It is permissible to suppress this error at a single documentation site if the cref must use a prefix because the type being mentioned is not findable by the compiler. For example, if a cref is mentioning a special attribute in the full framework but you're in a file that compiles against the portable framework, or if you want to reference a type at higher layer of Roslyn, you should suppress the error. You should not suppress the error just because you want to take a shortcut and avoid using the full syntax. -## [CA1501](https://docs.microsoft.com/visualstudio/code-quality/ca1501): Avoid excessive inheritance - |Item|Value| |-|-| -|Category|Maintainability| -|Enabled|False| +|Category|Documentation| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1501](https://docs.microsoft.com/visualstudio/code-quality/ca1501): Avoid excessive inheritance Deeply nested type hierarchies can be difficult to follow, understand, and maintain. This rule limits analysis to hierarchies in the same module. To fix a violation of this rule, derive the type from a base type that is less deep in the inheritance hierarchy or eliminate some of the intermediate base types. -## [CA1502](https://docs.microsoft.com/visualstudio/code-quality/ca1502): Avoid excessive complexity - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1502](https://docs.microsoft.com/visualstudio/code-quality/ca1502): Avoid excessive complexity Cyclomatic complexity measures the number of linearly independent paths through the method, which is determined by the number and complexity of conditional branches. A low cyclomatic complexity generally indicates a method that is easy to understand, test, and maintain. The cyclomatic complexity is calculated from a control flow graph of the method and is given as follows: `cyclomatic complexity = the number of edges - the number of nodes + 1`, where a node represents a logic branch point and an edge represents a line between nodes. -## [CA1505](https://docs.microsoft.com/visualstudio/code-quality/ca1505): Avoid unmaintainable code - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1505](https://docs.microsoft.com/visualstudio/code-quality/ca1505): Avoid unmaintainable code The maintainability index is calculated by using the following metrics: lines of code, program volume, and cyclomatic complexity. Program volume is a measure of the difficulty of understanding of a symbol that is based on the number of operators and operands in the code. Cyclomatic complexity is a measure of the structural complexity of the type or method. A low maintainability index indicates that code is probably difficult to maintain and would be a good candidate to redesign. -## [CA1506](https://docs.microsoft.com/visualstudio/code-quality/ca1506): Avoid excessive class coupling - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1506](https://docs.microsoft.com/visualstudio/code-quality/ca1506): Avoid excessive class coupling This rule measures class coupling by counting the number of unique type references that a symbol contains. Symbols that have a high degree of class coupling can be difficult to maintain. It is a good practice to have types and methods that exhibit low coupling and high cohesion. To fix this violation, try to redesign the code to reduce the number of types to which it is coupled. -## [CA1507](https://docs.microsoft.com/visualstudio/code-quality/ca1507): Use nameof to express symbol names - |Item|Value| |-|-| |Category|Maintainability| -|Enabled|True| +|Enabled|False| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1507](https://docs.microsoft.com/visualstudio/code-quality/ca1507): Use nameof to express symbol names Using nameof helps keep your code valid when refactoring. -## [CA1508](https://docs.microsoft.com/visualstudio/code-quality/ca1508): Avoid dead conditional code - |Item|Value| |-|-| |Category|Maintainability| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1508](https://docs.microsoft.com/visualstudio/code-quality/ca1508): Avoid dead conditional code '{0}' is never '{1}'. Remove or refactor the condition(s) to avoid dead code. -## [CA1509](https://docs.microsoft.com/visualstudio/code-quality/ca1509): Invalid entry in code metrics rule specification file - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1509](https://docs.microsoft.com/visualstudio/code-quality/ca1509): Invalid entry in code metrics rule specification file Invalid entry in code metrics rule specification file. -## [CA1700](https://docs.microsoft.com/visualstudio/code-quality/ca1700): Do not name enum values 'Reserved' - |Item|Value| |-|-| -|Category|Naming| +|Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1700](https://docs.microsoft.com/visualstudio/code-quality/ca1700): Do not name enum values 'Reserved' This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change. -## [CA1707](https://docs.microsoft.com/visualstudio/code-quality/ca1707): Identifiers should not contain underscores - |Item|Value| |-|-| |Category|Naming| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1707](https://docs.microsoft.com/visualstudio/code-quality/ca1707): Identifiers should not contain underscores By convention, identifier names do not contain the underscore (_) character. This rule checks namespaces, types, members, and parameters. -## [CA1708](https://docs.microsoft.com/visualstudio/code-quality/ca1708): Identifiers should differ by more than case - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1708](https://docs.microsoft.com/visualstudio/code-quality/ca1708): Identifiers should differ by more than case Identifiers for namespaces, types, members, and parameters cannot differ only by case because languages that target the common language runtime are not required to be case-sensitive. -## [CA1710](https://docs.microsoft.com/visualstudio/code-quality/ca1710): Identifiers should have correct suffix - |Item|Value| |-|-| |Category|Naming| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1710](https://docs.microsoft.com/visualstudio/code-quality/ca1710): Identifiers should have correct suffix By convention, the names of types that extend certain base types or that implement certain interfaces, or types that are derived from these types, have a suffix that is associated with the base type or interface. -## [CA1711](https://docs.microsoft.com/visualstudio/code-quality/ca1711): Identifiers should not have incorrect suffix - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1711](https://docs.microsoft.com/visualstudio/code-quality/ca1711): Identifiers should not have incorrect suffix By convention, only the names of types that extend certain base types or that implement certain interfaces, or types that are derived from these types, should end with specific reserved suffixes. Other type names should not use these reserved suffixes. -## [CA1712](https://docs.microsoft.com/visualstudio/code-quality/ca1712): Do not prefix enum values with type name - |Item|Value| |-|-| |Category|Naming| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1712](https://docs.microsoft.com/visualstudio/code-quality/ca1712): Do not prefix enum values with type name An enumeration's values should not start with the type name of the enumeration. -## [CA1713](https://docs.microsoft.com/visualstudio/code-quality/ca1713): Events should not have 'Before' or 'After' prefix - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1713](https://docs.microsoft.com/visualstudio/code-quality/ca1713): Events should not have 'Before' or 'After' prefix Event names should describe the action that raises the event. To name related events that are raised in a specific sequence, use the present or past tense to indicate the relative position in the sequence of actions. For example, when naming a pair of events that is raised when closing a resource, you might name it 'Closing' and 'Closed', instead of 'BeforeClose' and 'AfterClose'. -## [CA1714](https://docs.microsoft.com/visualstudio/code-quality/ca1714): Flags enums should have plural names - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1714](https://docs.microsoft.com/visualstudio/code-quality/ca1714): Flags enums should have plural names A public enumeration has the System.FlagsAttribute attribute, and its name does not end in ""s"". Types that are marked by using FlagsAttribute have names that are plural because the attribute indicates that more than one value can be specified. -## [CA1715](https://docs.microsoft.com/visualstudio/code-quality/ca1715): Identifiers should have correct prefix - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1715](https://docs.microsoft.com/visualstudio/code-quality/ca1715): Identifiers should have correct prefix The name of an externally visible interface does not start with an uppercase ""I"". The name of a generic type parameter on an externally visible type or method does not start with an uppercase ""T"". -## [CA1716](https://docs.microsoft.com/visualstudio/code-quality/ca1716): Identifiers should not match keywords - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1716](https://docs.microsoft.com/visualstudio/code-quality/ca1716): Identifiers should not match keywords A namespace name or a type name matches a reserved keyword in a programming language. Identifiers for namespaces and types should not match keywords that are defined by languages that target the common language runtime. -## [CA1717](https://docs.microsoft.com/visualstudio/code-quality/ca1717): Only FlagsAttribute enums should have plural names - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1717](https://docs.microsoft.com/visualstudio/code-quality/ca1717): Only FlagsAttribute enums should have plural names Naming conventions dictate that a plural name for an enumeration indicates that more than one value of the enumeration can be specified at the same time. -## [CA1720](https://docs.microsoft.com/visualstudio/code-quality/ca1720): Identifier contains type name - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1720](https://docs.microsoft.com/visualstudio/code-quality/ca1720): Identifier contains type name Names of parameters and members are better used to communicate their meaning than to describe their type, which is expected to be provided by development tools. For names of members, if a data type name must be used, use a language-independent name instead of a language-specific one. -## [CA1721](https://docs.microsoft.com/visualstudio/code-quality/ca1721): Property names should not match get methods - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1721](https://docs.microsoft.com/visualstudio/code-quality/ca1721): Property names should not match get methods The name of a public or protected member starts with ""Get"" and otherwise matches the name of a public or protected property. ""Get"" methods and properties should have names that clearly distinguish their function. -## [CA1724](https://docs.microsoft.com/visualstudio/code-quality/ca1724): Type names should not match namespaces - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1724](https://docs.microsoft.com/visualstudio/code-quality/ca1724): Type names should not match namespaces Type names should not match the names of namespaces that are defined in the .NET Framework class library. Violating this rule can reduce the usability of the library. -## [CA1725](https://docs.microsoft.com/visualstudio/code-quality/ca1725): Parameter names should match base declaration - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1725](https://docs.microsoft.com/visualstudio/code-quality/ca1725): Parameter names should match base declaration Consistent naming of parameters in an override hierarchy increases the usability of the method overrides. A parameter name in a derived method that differs from the name in the base declaration can cause confusion about whether the method is an override of the base method or a new overload of the method. -## [CA1801](https://docs.microsoft.com/visualstudio/code-quality/ca1801): Review unused parameters - |Item|Value| |-|-| -|Category|Usage| -|Enabled|True| +|Category|Naming| +|Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1801](https://docs.microsoft.com/visualstudio/code-quality/ca1801): Review unused parameters Avoid unused paramereters in your code. If the parameter cannot be removed, then change its name so it starts with an underscore and is optionally followed by an integer, such as '_', '_1', '_2', etc. These are treated as special discard symbol names. -## [CA1802](https://docs.microsoft.com/visualstudio/code-quality/ca1802): Use literals where appropriate - |Item|Value| |-|-| -|Category|Performance| +|Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1802](https://docs.microsoft.com/visualstudio/code-quality/ca1802): Use literals where appropriate A field is declared static and read-only (Shared and ReadOnly in Visual Basic), and is initialized by using a value that is computable at compile time. Because the value that is assigned to the targeted field is computable at compile time, change the declaration to a const (Const in Visual Basic) field so that the value is computed at compile time instead of at run?time. -## [CA1805](https://docs.microsoft.com/visualstudio/code-quality/ca1805): Do not initialize unnecessarily - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1805](https://docs.microsoft.com/visualstudio/code-quality/ca1805): Do not initialize unnecessarily The .NET runtime initializes all fields of reference types to their default values before running the constructor. In most cases, explicitly initializing a field to its default value in a constructor is redundant, adding maintenance costs and potentially degrading performance (such as with increased assembly size), and the explicit initialization can be removed. In some cases, such as with static readonly fields that permanently retain their default value, consider instead changing them to be constants or properties. -## [CA1806](https://docs.microsoft.com/visualstudio/code-quality/ca1806): Do not ignore method results - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1806](https://docs.microsoft.com/visualstudio/code-quality/ca1806): Do not ignore method results A new object is created but never used; or a method that creates and returns a new string is called and the new string is never used; or a COM or P/Invoke method returns an HRESULT or error code that is never used. -## [CA1812](https://docs.microsoft.com/visualstudio/code-quality/ca1812): Avoid uninstantiated internal classes - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1812](https://docs.microsoft.com/visualstudio/code-quality/ca1812): Avoid uninstantiated internal classes An instance of an assembly-level type is not created by code in the assembly. -## [CA1814](https://docs.microsoft.com/visualstudio/code-quality/ca1814): Prefer jagged arrays over multidimensional - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1814](https://docs.microsoft.com/visualstudio/code-quality/ca1814): Prefer jagged arrays over multidimensional A jagged array is an array whose elements are arrays. The arrays that make up the elements can be of different sizes, leading to less wasted space for some sets of data. -## [CA1815](https://docs.microsoft.com/visualstudio/code-quality/ca1815): Override equals and operator equals on value types - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1815](https://docs.microsoft.com/visualstudio/code-quality/ca1815): Override equals and operator equals on value types For value types, the inherited implementation of Equals uses the Reflection library and compares the contents of all fields. Reflection is computationally expensive, and comparing every field for equality might be unnecessary. If you expect users to compare or sort instances, or to use instances as hash table keys, your value type should implement Equals. -## [CA1819](https://docs.microsoft.com/visualstudio/code-quality/ca1819): Properties should not return arrays - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1819](https://docs.microsoft.com/visualstudio/code-quality/ca1819): Properties should not return arrays Arrays that are returned by properties are not write-protected, even when the property is read-only. To keep the array tamper-proof, the property must return a copy of the array. Typically, users will not understand the adverse performance implications of calling such a property. -## [CA1821](https://docs.microsoft.com/visualstudio/code-quality/ca1821): Remove empty Finalizers - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1821](https://docs.microsoft.com/visualstudio/code-quality/ca1821): Remove empty Finalizers Finalizers should be avoided where possible, to avoid the additional performance overhead involved in tracking object lifetime. -## [CA1822](https://docs.microsoft.com/visualstudio/code-quality/ca1822): Mark members as static - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1822](https://docs.microsoft.com/visualstudio/code-quality/ca1822): Mark members as static Members that do not access instance data or call instance methods can be marked as static. After you mark the methods as static, the compiler will emit nonvirtual call sites to these members. This can give you a measurable performance gain for performance-sensitive code. -## [CA1823](https://docs.microsoft.com/visualstudio/code-quality/ca1823): Avoid unused private fields - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1823](https://docs.microsoft.com/visualstudio/code-quality/ca1823): Avoid unused private fields Private fields were detected that do not appear to be accessed in the assembly. -## [CA2007](https://docs.microsoft.com/visualstudio/code-quality/ca2007): Consider calling ConfigureAwait on the awaited task - |Item|Value| |-|-| -|Category|Reliability| +|Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2007](https://docs.microsoft.com/visualstudio/code-quality/ca2007): Consider calling ConfigureAwait on the awaited task When an asynchronous method awaits a Task directly, continuation occurs in the same thread that created the task. Consider calling Task.ConfigureAwait(Boolean) to signal your intention for continuation. Call ConfigureAwait(false) on the task to schedule continuations to the thread pool, thereby avoiding a deadlock on the UI thread. Passing false is a good option for app-independent libraries. Calling ConfigureAwait(true) on the task has the same behavior as not explicitly calling ConfigureAwait. By explicitly calling this method, you're letting readers know you intentionally want to perform the continuation on the original synchronization context. -## [CA2011](https://docs.microsoft.com/visualstudio/code-quality/ca2011): Avoid infinite recursion - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2011](https://docs.microsoft.com/visualstudio/code-quality/ca2011): Avoid infinite recursion Do not assign the property within its setter. This call might result in an infinite recursion. -## [CA2109](https://docs.microsoft.com/visualstudio/code-quality/ca2109): Review visible event handlers - |Item|Value| |-|-| -|Category|Security| -|Enabled|False| +|Category|Reliability| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2109](https://docs.microsoft.com/visualstudio/code-quality/ca2109): Review visible event handlers A public or protected event-handling method was detected. Event-handling methods should not be exposed unless absolutely necessary. -## [CA2119](https://docs.microsoft.com/visualstudio/code-quality/ca2119): Seal methods that satisfy private interfaces - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2119](https://docs.microsoft.com/visualstudio/code-quality/ca2119): Seal methods that satisfy private interfaces An inheritable public type provides an overridable method implementation of an internal (Friend in Visual Basic) interface. To fix a violation of this rule, prevent the method from being overridden outside the assembly. -## [CA2200](https://docs.microsoft.com/visualstudio/code-quality/ca2200): Rethrow to preserve stack details - |Item|Value| |-|-| -|Category|Usage| +|Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2200](https://docs.microsoft.com/visualstudio/code-quality/ca2200): Rethrow to preserve stack details Re-throwing caught exception changes stack information -## [CA2211](https://docs.microsoft.com/visualstudio/code-quality/ca2211): Non-constant fields should not be visible - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2211](https://docs.microsoft.com/visualstudio/code-quality/ca2211): Non-constant fields should not be visible Static fields that are neither constants nor read-only are not thread-safe. Access to such a field must be carefully controlled and requires advanced programming techniques to synchronize access to the class object. -## [CA2214](https://docs.microsoft.com/visualstudio/code-quality/ca2214): Do not call overridable methods in constructors - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2214](https://docs.microsoft.com/visualstudio/code-quality/ca2214): Do not call overridable methods in constructors Virtual methods defined on the class should not be called from constructors. If a derived class has overridden the method, the derived class version will be called (before the derived class constructor is called). -## [CA2217](https://docs.microsoft.com/visualstudio/code-quality/ca2217): Do not mark enums with FlagsAttribute - |Item|Value| |-|-| |Category|Usage| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2217](https://docs.microsoft.com/visualstudio/code-quality/ca2217): Do not mark enums with FlagsAttribute An externally visible enumeration is marked by using FlagsAttribute, and it has one or more values that are not powers of two or a combination of the other defined values on the enumeration. -## [CA2218](https://docs.microsoft.com/visualstudio/code-quality/ca2218): Override GetHashCode on overriding Equals - |Item|Value| |-|-| |Category|Usage| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2218](https://docs.microsoft.com/visualstudio/code-quality/ca2218): Override GetHashCode on overriding Equals GetHashCode returns a value, based on the current instance, that is suited for hashing algorithms and data structures such as a hash table. Two objects that are the same type and are equal must return the same hash code. -## [CA2219](https://docs.microsoft.com/visualstudio/code-quality/ca2219): Do not raise exceptions in finally clauses - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2219](https://docs.microsoft.com/visualstudio/code-quality/ca2219): Do not raise exceptions in finally clauses When an exception is raised in a finally clause, the new exception hides the active exception. This makes the original error difficult to detect and debug. -## [CA2224](https://docs.microsoft.com/visualstudio/code-quality/ca2224): Override Equals on overloading operator equals - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2224](https://docs.microsoft.com/visualstudio/code-quality/ca2224): Override Equals on overloading operator equals A public type implements the equality operator but does not override Object.Equals. -## [CA2225](https://docs.microsoft.com/visualstudio/code-quality/ca2225): Operator overloads have named alternates - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2225](https://docs.microsoft.com/visualstudio/code-quality/ca2225): Operator overloads have named alternates An operator overload was detected, and the expected named alternative method was not found. The named alternative member provides access to the same functionality as the operator and is provided for developers who program in languages that do not support overloaded operators. -## [CA2226](https://docs.microsoft.com/visualstudio/code-quality/ca2226): Operators should have symmetrical overloads - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2226](https://docs.microsoft.com/visualstudio/code-quality/ca2226): Operators should have symmetrical overloads A type implements the equality or inequality operator and does not implement the opposite operator. -## [CA2227](https://docs.microsoft.com/visualstudio/code-quality/ca2227): Collection properties should be read only - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2227](https://docs.microsoft.com/visualstudio/code-quality/ca2227): Collection properties should be read only A writable collection property allows a user to replace the collection with a different collection. A read-only property stops the collection from being replaced but still allows the individual members to be set. -## [CA2231](https://docs.microsoft.com/visualstudio/code-quality/ca2231): Overload operator equals on overriding value type Equals - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2231](https://docs.microsoft.com/visualstudio/code-quality/ca2231): Overload operator equals on overriding value type Equals In most programming languages there is no default implementation of the equality operator (==) for value types. If your programming language supports operator overloads, you should consider implementing the equality operator. Its behavior should be identical to that of Equals. -## [CA2234](https://docs.microsoft.com/visualstudio/code-quality/ca2234): Pass system uri objects instead of strings - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2234](https://docs.microsoft.com/visualstudio/code-quality/ca2234): Pass system uri objects instead of strings A call is made to a method that has a string parameter whose name contains "uri", "URI", "urn", "URN", "url", or "URL". The declaring type of the method contains a corresponding method overload that has a System.Uri parameter. -## [CA2244](https://docs.microsoft.com/visualstudio/code-quality/ca2244): Do not duplicate indexed element initializations - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2244](https://docs.microsoft.com/visualstudio/code-quality/ca2244): Do not duplicate indexed element initializations Indexed elements in objects initializers must initialize unique elements. A duplicate index might overwrite a previous element initialization. -## [CA2245](https://docs.microsoft.com/visualstudio/code-quality/ca2245): Do not assign a property to itself - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2245](https://docs.microsoft.com/visualstudio/code-quality/ca2245): Do not assign a property to itself The property {0} should not be assigned to itself -## [CA2246](https://docs.microsoft.com/visualstudio/code-quality/ca2246): Assigning symbol and its member in the same statement - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2246](https://docs.microsoft.com/visualstudio/code-quality/ca2246): Assigning symbol and its member in the same statement Assigning to a symbol and its member (field/property) in the same statement is not recommended. It is not clear if the member access was intended to use symbol's old value prior to the assignment or new value from the assignment in this statement. For clarity, consider splitting the assignments into separate statements. +|Item|Value| +|-|-| +|Category|Usage| +|Enabled|True| +|Severity|Warning| +|CodeFix|False| +--- diff --git a/src/Microsoft.CodeQuality.Analyzers/RulesMissingDocumentation.md b/src/Microsoft.CodeQuality.Analyzers/RulesMissingDocumentation.md index 8add8039c5..75e0f77588 100644 --- a/src/Microsoft.CodeQuality.Analyzers/RulesMissingDocumentation.md +++ b/src/Microsoft.CodeQuality.Analyzers/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/Microsoft.NetCore.Analyzers/Microsoft.NetCore.Analyzers.md b/src/Microsoft.NetCore.Analyzers/Microsoft.NetCore.Analyzers.md index e52c28c06a..9bcfa06334 100644 --- a/src/Microsoft.NetCore.Analyzers/Microsoft.NetCore.Analyzers.md +++ b/src/Microsoft.NetCore.Analyzers/Microsoft.NetCore.Analyzers.md @@ -2,343 +2,307 @@ ## [CA1303](https://docs.microsoft.com/visualstudio/code-quality/ca1303): Do not pass literals as localized parameters +A method passes a string literal as a parameter to a constructor or method in the .NET Framework class library and that string should be localizable. To fix a violation of this rule, replace the string literal with a string retrieved through an instance of the ResourceManager class. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -A method passes a string literal as a parameter to a constructor or method in the .NET Framework class library and that string should be localizable. To fix a violation of this rule, replace the string literal with a string retrieved through an instance of the ResourceManager class. +--- ## [CA1304](https://docs.microsoft.com/visualstudio/code-quality/ca1304): Specify CultureInfo +A method or constructor calls a member that has an overload that accepts a System.Globalization.CultureInfo parameter, and the method or constructor does not call the overload that takes the CultureInfo parameter. When a CultureInfo or System.IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'CultureInfo' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -A method or constructor calls a member that has an overload that accepts a System.Globalization.CultureInfo parameter, and the method or constructor does not call the overload that takes the CultureInfo parameter. When a CultureInfo or System.IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'CultureInfo' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'. +--- ## [CA1305](https://docs.microsoft.com/visualstudio/code-quality/ca1305): Specify IFormatProvider +A method or constructor calls one or more members that have overloads that accept a System.IFormatProvider parameter, and the method or constructor does not call the overload that takes the IFormatProvider parameter. When a System.Globalization.CultureInfo or IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be based on the input from/output displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider'. Otherwise, if the result will be stored and accessed by software, such as when it is loaded from disk/database and when it is persisted to disk/database, specify 'CultureInfo.InvariantCulture'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -A method or constructor calls one or more members that have overloads that accept a System.IFormatProvider parameter, and the method or constructor does not call the overload that takes the IFormatProvider parameter. When a System.Globalization.CultureInfo or IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be based on the input from/output displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider'. Otherwise, if the result will be stored and accessed by software, such as when it is loaded from disk/database and when it is persisted to disk/database, specify 'CultureInfo.InvariantCulture'. +--- ## [CA1307](https://docs.microsoft.com/visualstudio/code-quality/ca1307): Specify StringComparison for clarity +A string comparison operation uses a method overload that does not set a StringComparison parameter. It is recommended to use the overload with StringComparison parameter for clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A string comparison operation uses a method overload that does not set a StringComparison parameter. It is recommended to use the overload with StringComparison parameter for clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. +--- ## [CA1308](https://docs.microsoft.com/visualstudio/code-quality/ca1308): Normalize strings to uppercase +Strings should be normalized to uppercase. A small group of characters cannot make a round trip when they are converted to lowercase. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Strings should be normalized to uppercase. A small group of characters cannot make a round trip when they are converted to lowercase. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters. +--- ## [CA1309](https://docs.microsoft.com/visualstudio/code-quality/ca1309): Use ordinal string comparison +A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable. + |Item|Value| |-|-| |Category|Globalization| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable. +--- ## [CA1310](https://docs.microsoft.com/visualstudio/code-quality/ca1310): Specify StringComparison for correctness +A string comparison operation uses a method overload that does not set a StringComparison parameter, hence its behavior could vary based on the current user's locale settings. It is strongly recommended to use the overload with StringComparison parameter for correctness and clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -A string comparison operation uses a method overload that does not set a StringComparison parameter, hence its behavior could vary based on the current user's locale settings. It is strongly recommended to use the overload with StringComparison parameter for correctness and clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. +--- ## [CA1401](https://docs.microsoft.com/visualstudio/code-quality/ca1401): P/Invokes should not be visible +A public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic). Such methods should not be exposed. + |Item|Value| |-|-| |Category|Interoperability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -A public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic). Such methods should not be exposed. +--- ## [CA1416](https://docs.microsoft.com/visualstudio/code-quality/ca1416): Validate platform compatibility +Using platform dependent API on a component makes the code no longer work across all platforms. + |Item|Value| |-|-| |Category|Interoperability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Using platform dependent API on a component makes the code no longer work across all platforms. +--- ## [CA1417](https://docs.microsoft.com/visualstudio/code-quality/ca1417): Do not use 'OutAttribute' on string parameters for P/Invokes +String parameters passed by value with the 'OutAttribute' can destabilize the runtime if the string is an interned string. + |Item|Value| |-|-| |Category|Interoperability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -String parameters passed by value with the 'OutAttribute' can destabilize the runtime if the string is an interned string. +--- ## [CA1810](https://docs.microsoft.com/visualstudio/code-quality/ca1810): Initialize reference type static fields inline +A reference type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. + |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -A reference type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. +--- ## [CA1813](https://docs.microsoft.com/visualstudio/code-quality/ca1813): Avoid unsealed attributes +The .NET Framework class library provides methods for retrieving custom attributes. By default, these methods search the attribute inheritance hierarchy. Sealing the attribute eliminates the search through the inheritance hierarchy and can improve performance. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -The .NET Framework class library provides methods for retrieving custom attributes. By default, these methods search the attribute inheritance hierarchy. Sealing the attribute eliminates the search through the inheritance hierarchy and can improve performance. +--- ## [CA1816](https://docs.microsoft.com/visualstudio/code-quality/ca1816): Dispose methods should call SuppressFinalize +A method that is an implementation of Dispose does not call GC.SuppressFinalize; or a method that is not an implementation of Dispose calls GC.SuppressFinalize; or a method calls GC.SuppressFinalize and passes something other than this (Me in Visual?Basic). + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -A method that is an implementation of Dispose does not call GC.SuppressFinalize; or a method that is not an implementation of Dispose calls GC.SuppressFinalize; or a method calls GC.SuppressFinalize and passes something other than this (Me in Visual?Basic). +--- ## [CA1820](https://docs.microsoft.com/visualstudio/code-quality/ca1820): Test for empty strings using string length -|Item|Value| -|-|-| -|Category|Performance| -|Enabled|True| -|Severity|Warning| -|CodeFix|True| - -### Rule description - Comparing strings by using the String.Length property or the String.IsNullOrEmpty method is significantly faster than using Equals. -## [CA1824](https://docs.microsoft.com/visualstudio/code-quality/ca1824): Mark assemblies with NeutralResourcesLanguageAttribute - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1824](https://docs.microsoft.com/visualstudio/code-quality/ca1824): Mark assemblies with NeutralResourcesLanguageAttribute The NeutralResourcesLanguage attribute informs the ResourceManager of the language that was used to display the resources of a neutral culture for an assembly. This improves lookup performance for the first resource that you load and can reduce your working set. -## [CA1825](https://docs.microsoft.com/visualstudio/code-quality/ca1825): Avoid zero-length array allocations - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1825](https://docs.microsoft.com/visualstudio/code-quality/ca1825): Avoid zero-length array allocations Avoid unnecessary zero-length array allocations. Use {0} instead. -## [CA1826](https://docs.microsoft.com/visualstudio/code-quality/ca1826): Do not use Enumerable methods on indexable collections - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1826](https://docs.microsoft.com/visualstudio/code-quality/ca1826): Do not use Enumerable methods on indexable collections This collection is directly indexable. Going through LINQ here causes unnecessary allocations and CPU work. -## [CA1827](https://docs.microsoft.com/visualstudio/code-quality/ca1827): Do not use Count() or LongCount() when Any() can be used - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1827](https://docs.microsoft.com/visualstudio/code-quality/ca1827): Do not use Count() or LongCount() when Any() can be used For non-empty collections, Count() and LongCount() enumerate the entire sequence, while Any() stops at the first item or the first item that satisfies a condition. -## [CA1828](https://docs.microsoft.com/visualstudio/code-quality/ca1828): Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1828](https://docs.microsoft.com/visualstudio/code-quality/ca1828): Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used For non-empty collections, CountAsync() and LongCountAsync() enumerate the entire sequence, while AnyAsync() stops at the first item or the first item that satisfies a condition. -## [CA1829](https://docs.microsoft.com/visualstudio/code-quality/ca1829): Use Length/Count property instead of Count() when available - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1829](https://docs.microsoft.com/visualstudio/code-quality/ca1829): Use Length/Count property instead of Count() when available Enumerable.Count() potentially enumerates the sequence while a Length/Count property is a direct access. -## [CA1830](https://docs.microsoft.com/visualstudio/code-quality/ca1830): Prefer strongly-typed Append and Insert method overloads on StringBuilder - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1830](https://docs.microsoft.com/visualstudio/code-quality/ca1830): Prefer strongly-typed Append and Insert method overloads on StringBuilder StringBuilder.Append and StringBuilder.Insert provide overloads for multiple types beyond System.String. When possible, prefer the strongly-typed overloads over using ToString() and the string-based overload. -## [CA1831](https://docs.microsoft.com/visualstudio/code-quality/ca1831): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1831](https://docs.microsoft.com/visualstudio/code-quality/ca1831): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on string values produces a copy of requested portion of the string. This copy is usually unnecessary when it is implicitly used as a ReadOnlySpan or ReadOnlyMemory value. Use the AsSpan method to avoid the unnecessary copy. -## [CA1832](https://docs.microsoft.com/visualstudio/code-quality/ca1832): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1832](https://docs.microsoft.com/visualstudio/code-quality/ca1832): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on array values produces a copy of requested portion of the array. This copy is usually unnecessary when it is implicitly used as a ReadOnlySpan or ReadOnlyMemory value. Use the AsSpan method to avoid the unnecessary copy. -## [CA1833](https://docs.microsoft.com/visualstudio/code-quality/ca1833): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1833](https://docs.microsoft.com/visualstudio/code-quality/ca1833): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on array values produces a copy of requested portion of the array. This copy is often unwanted when it is implicitly used as a Span or Memory value. Use the AsSpan method to avoid the copy. -## [CA1834](https://docs.microsoft.com/visualstudio/code-quality/ca1834): Consider using 'StringBuilder.Append(char)' when applicable - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1834](https://docs.microsoft.com/visualstudio/code-quality/ca1834): Consider using 'StringBuilder.Append(char)' when applicable 'StringBuilder.Append(char)' is more efficient than 'StringBuilder.Append(string)' when the string is a single character. When calling 'Append' with a constant, prefer using a constant char rather than a constant string containing one character. -## [CA1835](https://docs.microsoft.com/visualstudio/code-quality/ca1835): Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description - -'Stream' has a 'ReadAsync' overload that takes a 'Memory' as the first argument, and a 'WriteAsync' overload that takes a 'ReadOnlyMemory' as the first argument. Prefer calling the memory based overloads, which are more efficient. +## [CA1835](https://docs.microsoft.com/visualstudio/code-quality/ca1835): Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' -## [CA1836](https://docs.microsoft.com/visualstudio/code-quality/ca1836): Prefer IsEmpty over Count +'Stream' has a 'ReadAsync' overload that takes a 'Memory\' as the first argument, and a 'WriteAsync' overload that takes a 'ReadOnlyMemory\' as the first argument. Prefer calling the memory based overloads, which are more efficient. |Item|Value| |-|-| @@ -346,1503 +310,1396 @@ The Range-based indexer on array values produces a copy of requested portion of |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1836](https://docs.microsoft.com/visualstudio/code-quality/ca1836): Prefer IsEmpty over Count For determining whether the object contains or not any items, prefer using 'IsEmpty' property rather than retrieving the number of items from the 'Count' property and comparing it to 0 or 1. -## [CA1837](https://docs.microsoft.com/visualstudio/code-quality/ca1837): Use 'Environment.ProcessId' - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1837](https://docs.microsoft.com/visualstudio/code-quality/ca1837): Use 'Environment.ProcessId' 'Environment.ProcessId' is simpler and faster than 'Process.GetCurrentProcess().Id'. -## [CA1838](https://docs.microsoft.com/visualstudio/code-quality/ca1838): Avoid 'StringBuilder' parameters for P/Invokes - |Item|Value| |-|-| |Category|Performance| -|Enabled|False| +|Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1838](https://docs.microsoft.com/visualstudio/code-quality/ca1838): Avoid 'StringBuilder' parameters for P/Invokes Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. -## [CA2000](https://docs.microsoft.com/visualstudio/code-quality/ca2000): Dispose objects before losing scope - |Item|Value| |-|-| -|Category|Reliability| -|Enabled|True| +|Category|Performance| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2000](https://docs.microsoft.com/visualstudio/code-quality/ca2000): Dispose objects before losing scope If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead. -## [CA2002](https://docs.microsoft.com/visualstudio/code-quality/ca2002): Do not lock on objects with weak identity - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2002](https://docs.microsoft.com/visualstudio/code-quality/ca2002): Do not lock on objects with weak identity An object is said to have a weak identity when it can be directly accessed across application domain boundaries. A thread that tries to acquire a lock on an object that has a weak identity can be blocked by a second thread in a different application domain that has a lock on the same object. -## [CA2008](https://docs.microsoft.com/visualstudio/code-quality/ca2008): Do not create tasks without passing a TaskScheduler - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2008](https://docs.microsoft.com/visualstudio/code-quality/ca2008): Do not create tasks without passing a TaskScheduler Do not create tasks unless you are using one of the overloads that takes a TaskScheduler. The default is to schedule on TaskScheduler.Current, which would lead to deadlocks. Either use TaskScheduler.Default to schedule on the thread pool, or explicitly pass TaskScheduler.Current to make your intentions clear. -## [CA2009](https://docs.microsoft.com/visualstudio/code-quality/ca2009): Do not call ToImmutableCollection on an ImmutableCollection value - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2009](https://docs.microsoft.com/visualstudio/code-quality/ca2009): Do not call ToImmutableCollection on an ImmutableCollection value Do not call {0} on an {1} value -## [CA2012](https://docs.microsoft.com/visualstudio/code-quality/ca2012): Use ValueTasks correctly - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2012](https://docs.microsoft.com/visualstudio/code-quality/ca2012): Use ValueTasks correctly ValueTasks returned from member invocations are intended to be directly awaited. Attempts to consume a ValueTask multiple times or to directly access one's result before it's known to be completed may result in an exception or corruption. Ignoring such a ValueTask is likely an indication of a functional bug and may degrade performance. -## [CA2013](https://docs.microsoft.com/visualstudio/code-quality/ca2013): Do not use ReferenceEquals with value types - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2013](https://docs.microsoft.com/visualstudio/code-quality/ca2013): Do not use ReferenceEquals with value types Value type typed arguments are uniquely boxed for each call to this method, therefore the result is always false. -## [CA2014](https://docs.microsoft.com/visualstudio/code-quality/ca2014): Do not use stackalloc in loops - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2014](https://docs.microsoft.com/visualstudio/code-quality/ca2014): Do not use stackalloc in loops Stack space allocated by a stackalloc is only released at the end of the current method's invocation. Using it in a loop can result in unbounded stack growth and eventual stack overflow conditions. -## [CA2015](https://docs.microsoft.com/visualstudio/code-quality/ca2015): Do not define finalizers for types derived from MemoryManager - |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2015](https://docs.microsoft.com/visualstudio/code-quality/ca2015): Do not define finalizers for types derived from MemoryManager\ -Adding a finalizer to a type derived from MemoryManager may permit memory to be freed while it is still in use by a Span. - -## [CA2016](https://docs.microsoft.com/visualstudio/code-quality/ca2016): Forward the 'CancellationToken' parameter to methods that take one +Adding a finalizer to a type derived from MemoryManager\ may permit memory to be freed while it is still in use by a Span\. |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2016](https://docs.microsoft.com/visualstudio/code-quality/ca2016): Forward the 'CancellationToken' parameter to methods that take one Forward the 'CancellationToken' parameter to methods that take one to ensure the operation cancellation notifications gets properly propagated, or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token. -## [CA2100](https://docs.microsoft.com/visualstudio/code-quality/ca2100): Review SQL queries for security vulnerabilities - |Item|Value| |-|-| -|Category|Security| +|Category|Reliability| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2100](https://docs.microsoft.com/visualstudio/code-quality/ca2100): Review SQL queries for security vulnerabilities SQL queries that directly use user input can be vulnerable to SQL injection attacks. Review this SQL query for potential vulnerabilities, and consider using a parameterized SQL query. -## [CA2101](https://docs.microsoft.com/visualstudio/code-quality/ca2101): Specify marshaling for P/Invoke string arguments - |Item|Value| |-|-| -|Category|Globalization| +|Category|Security| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2101](https://docs.microsoft.com/visualstudio/code-quality/ca2101): Specify marshaling for P/Invoke string arguments A platform invoke member allows partially trusted callers, has a string parameter, and does not explicitly marshal the string. This can cause a potential security vulnerability. -## [CA2201](https://docs.microsoft.com/visualstudio/code-quality/ca2201): Do not raise reserved exception types - |Item|Value| |-|-| -|Category|Usage| -|Enabled|False| +|Category|Globalization| +|Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2201](https://docs.microsoft.com/visualstudio/code-quality/ca2201): Do not raise reserved exception types An exception of type that is not sufficiently specific or reserved by the runtime should never be raised by user code. This makes the original error difficult to detect and debug. If this exception instance might be thrown, use a different exception type. -## [CA2207](https://docs.microsoft.com/visualstudio/code-quality/ca2207): Initialize value type static fields inline - |Item|Value| |-|-| |Category|Usage| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2207](https://docs.microsoft.com/visualstudio/code-quality/ca2207): Initialize value type static fields inline A value type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. -## [CA2208](https://docs.microsoft.com/visualstudio/code-quality/ca2208): Instantiate argument exceptions correctly - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2208](https://docs.microsoft.com/visualstudio/code-quality/ca2208): Instantiate argument exceptions correctly A call is made to the default (parameterless) constructor of an exception type that is or derives from ArgumentException, or an incorrect string argument is passed to a parameterized constructor of an exception type that is or derives from ArgumentException. -## [CA2213](https://docs.microsoft.com/visualstudio/code-quality/ca2213): Disposable fields should be disposed - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2213](https://docs.microsoft.com/visualstudio/code-quality/ca2213): Disposable fields should be disposed A type that implements System.IDisposable declares fields that are of types that also implement IDisposable. The Dispose method of the field is not called by the Dispose method of the declaring type. To fix a violation of this rule, call Dispose on fields that are of types that implement IDisposable if you are responsible for allocating and releasing the unmanaged resources held by the field. -## [CA2215](https://docs.microsoft.com/visualstudio/code-quality/ca2215): Dispose methods should call base class dispose - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2215](https://docs.microsoft.com/visualstudio/code-quality/ca2215): Dispose methods should call base class dispose A type that implements System.IDisposable inherits from a type that also implements IDisposable. The Dispose method of the inheriting type does not call the Dispose method of the parent type. To fix a violation of this rule, call base.Dispose in your Dispose method. -## [CA2216](https://docs.microsoft.com/visualstudio/code-quality/ca2216): Disposable types should declare finalizer - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2216](https://docs.microsoft.com/visualstudio/code-quality/ca2216): Disposable types should declare finalizer A type that implements System.IDisposable and has fields that suggest the use of unmanaged resources does not implement a finalizer, as described by Object.Finalize. -## [CA2229](https://docs.microsoft.com/visualstudio/code-quality/ca2229): Implement serialization constructors - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2229](https://docs.microsoft.com/visualstudio/code-quality/ca2229): Implement serialization constructors To fix a violation of this rule, implement the serialization constructor. For a sealed class, make the constructor private; otherwise, make it protected. -## [CA2235](https://docs.microsoft.com/visualstudio/code-quality/ca2235): Mark all non-serializable fields - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2235](https://docs.microsoft.com/visualstudio/code-quality/ca2235): Mark all non-serializable fields An instance field of a type that is not serializable is declared in a type that is serializable. -## [CA2237](https://docs.microsoft.com/visualstudio/code-quality/ca2237): Mark ISerializable types with serializable - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA2237](https://docs.microsoft.com/visualstudio/code-quality/ca2237): Mark ISerializable types with serializable To be recognized by the common language runtime as serializable, types must be marked by using the SerializableAttribute attribute even when the type uses a custom serialization routine through implementation of the ISerializable interface. -## [CA2241](https://docs.microsoft.com/visualstudio/code-quality/ca2241): Provide correct arguments to formatting methods - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2241](https://docs.microsoft.com/visualstudio/code-quality/ca2241): Provide correct arguments to formatting methods The format argument that is passed to System.String.Format does not contain a format item that corresponds to each object argument, or vice versa. -## [CA2242](https://docs.microsoft.com/visualstudio/code-quality/ca2242): Test for NaN correctly - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2242](https://docs.microsoft.com/visualstudio/code-quality/ca2242): Test for NaN correctly This expression tests a value against Single.Nan or Double.Nan. Use Single.IsNan(Single) or Double.IsNan(Double) to test the value. -## [CA2243](https://docs.microsoft.com/visualstudio/code-quality/ca2243): Attribute string literals should parse correctly - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2243](https://docs.microsoft.com/visualstudio/code-quality/ca2243): Attribute string literals should parse correctly The string literal parameter of an attribute does not parse correctly for a URL, a GUID, or a version. -## [CA2247](https://docs.microsoft.com/visualstudio/code-quality/ca2247): Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2247](https://docs.microsoft.com/visualstudio/code-quality/ca2247): Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum TaskCompletionSource has constructors that take TaskCreationOptions that control the underlying Task, and constructors that take object state that's stored in the task. Accidentally passing a TaskContinuationOptions instead of a TaskCreationOptions will result in the call treating the options as state. -## [CA2248](https://docs.microsoft.com/visualstudio/code-quality/ca2248): Provide correct 'enum' argument to 'Enum.HasFlag' - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2248](https://docs.microsoft.com/visualstudio/code-quality/ca2248): Provide correct 'enum' argument to 'Enum.HasFlag' 'Enum.HasFlag' method expects the 'enum' argument to be of the same 'enum' type as the instance on which the method is invoked and that this 'enum' is marked with 'System.FlagsAttribute'. If these are different 'enum' types, an unhandled exception will be thrown at runtime. If the 'enum' type is not marked with 'System.FlagsAttribute' the call will always return 'false' at runtime. -## [CA2249](https://docs.microsoft.com/visualstudio/code-quality/ca2249): Consider using 'string.Contains' instead of 'string.IndexOf' - |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA2249](https://docs.microsoft.com/visualstudio/code-quality/ca2249): Consider using 'string.Contains' instead of 'string.IndexOf' Calls to 'string.IndexOf' where the result is used to check for the presence/absence of a substring can be replaced by 'string.Contains'. -## [CA2300](https://docs.microsoft.com/visualstudio/code-quality/ca2300): Do not use insecure deserializer BinaryFormatter - |Item|Value| |-|-| -|Category|Security| -|Enabled|False| +|Category|Usage| +|Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA2300](https://docs.microsoft.com/visualstudio/code-quality/ca2300): Do not use insecure deserializer BinaryFormatter The method '{0}' is insecure when deserializing untrusted data. If you need to instead detect BinaryFormatter deserialization without a SerializationBinder set, then disable rule CA2300, and enable rules CA2301 and CA2302. -## [CA2301](https://docs.microsoft.com/visualstudio/code-quality/ca2301): Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2301](https://docs.microsoft.com/visualstudio/code-quality/ca2301): Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2302](https://docs.microsoft.com/visualstudio/code-quality/ca2302): Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2302](https://docs.microsoft.com/visualstudio/code-quality/ca2302): Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2305](https://docs.microsoft.com/visualstudio/code-quality/ca2305): Do not use insecure deserializer LosFormatter - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2305](https://docs.microsoft.com/visualstudio/code-quality/ca2305): Do not use insecure deserializer LosFormatter The method '{0}' is insecure when deserializing untrusted data. -## [CA2310](https://docs.microsoft.com/visualstudio/code-quality/ca2310): Do not use insecure deserializer NetDataContractSerializer - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2310](https://docs.microsoft.com/visualstudio/code-quality/ca2310): Do not use insecure deserializer NetDataContractSerializer The method '{0}' is insecure when deserializing untrusted data. If you need to instead detect NetDataContractSerializer deserialization without a SerializationBinder set, then disable rule CA2310, and enable rules CA2311 and CA2312. -## [CA2311](https://docs.microsoft.com/visualstudio/code-quality/ca2311): Do not deserialize without first setting NetDataContractSerializer.Binder - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2311](https://docs.microsoft.com/visualstudio/code-quality/ca2311): Do not deserialize without first setting NetDataContractSerializer.Binder The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2312](https://docs.microsoft.com/visualstudio/code-quality/ca2312): Ensure NetDataContractSerializer.Binder is set before deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2312](https://docs.microsoft.com/visualstudio/code-quality/ca2312): Ensure NetDataContractSerializer.Binder is set before deserializing The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2315](https://docs.microsoft.com/visualstudio/code-quality/ca2315): Do not use insecure deserializer ObjectStateFormatter - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2315](https://docs.microsoft.com/visualstudio/code-quality/ca2315): Do not use insecure deserializer ObjectStateFormatter The method '{0}' is insecure when deserializing untrusted data. -## [CA2321](https://docs.microsoft.com/visualstudio/code-quality/ca2321): Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2321](https://docs.microsoft.com/visualstudio/code-quality/ca2321): Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver The method '{0}' is insecure when deserializing untrusted data with a JavaScriptSerializer initialized with a SimpleTypeResolver. Initialize JavaScriptSerializer without a JavaScriptTypeResolver specified, or initialize with a JavaScriptTypeResolver that limits the types of objects in the deserialized object graph. -## [CA2322](https://docs.microsoft.com/visualstudio/code-quality/ca2322): Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2322](https://docs.microsoft.com/visualstudio/code-quality/ca2322): Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing The method '{0}' is insecure when deserializing untrusted data with a JavaScriptSerializer initialized with a SimpleTypeResolver. Ensure that the JavaScriptSerializer is initialized without a JavaScriptTypeResolver specified, or initialized with a JavaScriptTypeResolver that limits the types of objects in the deserialized object graph. -## [CA2326](https://docs.microsoft.com/visualstudio/code-quality/ca2326): Do not use TypeNameHandling values other than None - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2326](https://docs.microsoft.com/visualstudio/code-quality/ca2326): Do not use TypeNameHandling values other than None Deserializing JSON when using a TypeNameHandling value other than None can be insecure. If you need to instead detect Json.NET deserialization when a SerializationBinder isn't specified, then disable rule CA2326, and enable rules CA2327, CA2328, CA2329, and CA2330. -## [CA2327](https://docs.microsoft.com/visualstudio/code-quality/ca2327): Do not use insecure JsonSerializerSettings - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2327](https://docs.microsoft.com/visualstudio/code-quality/ca2327): Do not use insecure JsonSerializerSettings When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using JsonSerializerSettings, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2328](https://docs.microsoft.com/visualstudio/code-quality/ca2328): Ensure that JsonSerializerSettings are secure - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2328](https://docs.microsoft.com/visualstudio/code-quality/ca2328): Ensure that JsonSerializerSettings are secure When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using JsonSerializerSettings, ensure TypeNameHandling.None is specified, or for values other than None, ensure a SerializationBinder is specified to restrict deserialized types. -## [CA2329](https://docs.microsoft.com/visualstudio/code-quality/ca2329): Do not deserialize with JsonSerializer using an insecure configuration - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2329](https://docs.microsoft.com/visualstudio/code-quality/ca2329): Do not deserialize with JsonSerializer using an insecure configuration When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using deserializing JsonSerializer, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2330](https://docs.microsoft.com/visualstudio/code-quality/ca2330): Ensure that JsonSerializer has a secure configuration when deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2330](https://docs.microsoft.com/visualstudio/code-quality/ca2330): Ensure that JsonSerializer has a secure configuration when deserializing When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using deserializing JsonSerializer, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2350](https://docs.microsoft.com/visualstudio/code-quality/ca2350): Do not use DataTable.ReadXml() with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2350](https://docs.microsoft.com/visualstudio/code-quality/ca2350): Do not use DataTable.ReadXml() with untrusted data The method '{0}' is insecure when deserializing untrusted data -## [CA2351](https://docs.microsoft.com/visualstudio/code-quality/ca2351): Do not use DataSet.ReadXml() with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2351](https://docs.microsoft.com/visualstudio/code-quality/ca2351): Do not use DataSet.ReadXml() with untrusted data The method '{0}' is insecure when deserializing untrusted data -## [CA2352](https://docs.microsoft.com/visualstudio/code-quality/ca2352): Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2352](https://docs.microsoft.com/visualstudio/code-quality/ca2352): Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks When deserializing untrusted input with an IFormatter-based serializer, deserializing a {0} object is insecure. '{1}' either is or derives from {0}. -## [CA2353](https://docs.microsoft.com/visualstudio/code-quality/ca2353): Unsafe DataSet or DataTable in serializable type - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2353](https://docs.microsoft.com/visualstudio/code-quality/ca2353): Unsafe DataSet or DataTable in serializable type When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2354](https://docs.microsoft.com/visualstudio/code-quality/ca2354): Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2354](https://docs.microsoft.com/visualstudio/code-quality/ca2354): Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2355](https://docs.microsoft.com/visualstudio/code-quality/ca2355): Unsafe DataSet or DataTable type found in deserializable object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2355](https://docs.microsoft.com/visualstudio/code-quality/ca2355): Unsafe DataSet or DataTable type found in deserializable object graph When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2356](https://docs.microsoft.com/visualstudio/code-quality/ca2356): Unsafe DataSet or DataTable type in web deserializable object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2356](https://docs.microsoft.com/visualstudio/code-quality/ca2356): Unsafe DataSet or DataTable type in web deserializable object graph When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2361](https://docs.microsoft.com/visualstudio/code-quality/ca2361): Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2361](https://docs.microsoft.com/visualstudio/code-quality/ca2361): Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data The method '{0}' is insecure when deserializing untrusted data. Make sure that autogenerated class containing the '{0}' call is not deserialized with untrusted data. -## [CA2362](https://docs.microsoft.com/visualstudio/code-quality/ca2362): Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2362](https://docs.microsoft.com/visualstudio/code-quality/ca2362): Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks When deserializing untrusted input with an IFormatter-based serializer, deserializing a {0} object is insecure. '{1}' either is or derives from {0}. Ensure that the autogenerated type is never deserialized with untrusted data. -## [CA3001](https://docs.microsoft.com/visualstudio/code-quality/ca3001): Review code for SQL injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3001](https://docs.microsoft.com/visualstudio/code-quality/ca3001): Review code for SQL injection vulnerabilities Potential SQL injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3002](https://docs.microsoft.com/visualstudio/code-quality/ca3002): Review code for XSS vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3002](https://docs.microsoft.com/visualstudio/code-quality/ca3002): Review code for XSS vulnerabilities Potential cross-site scripting (XSS) vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3003](https://docs.microsoft.com/visualstudio/code-quality/ca3003): Review code for file path injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3003](https://docs.microsoft.com/visualstudio/code-quality/ca3003): Review code for file path injection vulnerabilities Potential file path injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3004](https://docs.microsoft.com/visualstudio/code-quality/ca3004): Review code for information disclosure vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3004](https://docs.microsoft.com/visualstudio/code-quality/ca3004): Review code for information disclosure vulnerabilities Potential information disclosure vulnerability was found where '{0}' in method '{1}' may contain unintended information from '{2}' in method '{3}'. -## [CA3005](https://docs.microsoft.com/visualstudio/code-quality/ca3005): Review code for LDAP injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3005](https://docs.microsoft.com/visualstudio/code-quality/ca3005): Review code for LDAP injection vulnerabilities Potential LDAP injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3006](https://docs.microsoft.com/visualstudio/code-quality/ca3006): Review code for process command injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3006](https://docs.microsoft.com/visualstudio/code-quality/ca3006): Review code for process command injection vulnerabilities Potential process command injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3007](https://docs.microsoft.com/visualstudio/code-quality/ca3007): Review code for open redirect vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3007](https://docs.microsoft.com/visualstudio/code-quality/ca3007): Review code for open redirect vulnerabilities Potential open redirect vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3008](https://docs.microsoft.com/visualstudio/code-quality/ca3008): Review code for XPath injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3008](https://docs.microsoft.com/visualstudio/code-quality/ca3008): Review code for XPath injection vulnerabilities Potential XPath injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3009](https://docs.microsoft.com/visualstudio/code-quality/ca3009): Review code for XML injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3009](https://docs.microsoft.com/visualstudio/code-quality/ca3009): Review code for XML injection vulnerabilities Potential XML injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3010](https://docs.microsoft.com/visualstudio/code-quality/ca3010): Review code for XAML injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3010](https://docs.microsoft.com/visualstudio/code-quality/ca3010): Review code for XAML injection vulnerabilities Potential XAML injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3011](https://docs.microsoft.com/visualstudio/code-quality/ca3011): Review code for DLL injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3011](https://docs.microsoft.com/visualstudio/code-quality/ca3011): Review code for DLL injection vulnerabilities Potential DLL injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3012](https://docs.microsoft.com/visualstudio/code-quality/ca3012): Review code for regex injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3012](https://docs.microsoft.com/visualstudio/code-quality/ca3012): Review code for regex injection vulnerabilities Potential regex injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3061](https://docs.microsoft.com/visualstudio/code-quality/ca3061): Do Not Add Schema By URL - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3061](https://docs.microsoft.com/visualstudio/code-quality/ca3061): Do Not Add Schema By URL This overload of XmlSchemaCollection.Add method internally enables DTD processing on the XML reader instance used, and uses UrlResolver for resolving external XML entities. The outcome is information disclosure. Content from file system or network shares for the machine processing the XML can be exposed to attacker. In addition, an attacker can use this as a DoS vector. -## [CA5350](https://docs.microsoft.com/visualstudio/code-quality/ca5350): Do Not Use Weak Cryptographic Algorithms - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5350](https://docs.microsoft.com/visualstudio/code-quality/ca5350): Do Not Use Weak Cryptographic Algorithms Cryptographic algorithms degrade over time as attacks become for advances to attacker get access to more computation. Depending on the type and application of this cryptographic algorithm, further degradation of the cryptographic strength of it may allow attackers to read enciphered messages, tamper with enciphered  messages, forge digital signatures, tamper with hashed content, or otherwise compromise any cryptosystem based on this algorithm. Replace encryption uses with the AES algorithm (AES-256, AES-192 and AES-128 are acceptable) with a key length greater than or equal to 128 bits. Replace hashing uses with a hashing function in the SHA-2 family, such as SHA-2 512, SHA-2 384, or SHA-2 256. -## [CA5351](https://docs.microsoft.com/visualstudio/code-quality/ca5351): Do Not Use Broken Cryptographic Algorithms - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5351](https://docs.microsoft.com/visualstudio/code-quality/ca5351): Do Not Use Broken Cryptographic Algorithms An attack making it computationally feasible to break this algorithm exists. This allows attackers to break the cryptographic guarantees it is designed to provide. Depending on the type and application of this cryptographic algorithm, this may allow attackers to read enciphered messages, tamper with enciphered  messages, forge digital signatures, tamper with hashed content, or otherwise compromise any cryptosystem based on this algorithm. Replace encryption uses with the AES algorithm (AES-256, AES-192 and AES-128 are acceptable) with a key length greater than or equal to 128 bits. Replace hashing uses with a hashing function in the SHA-2 family, such as SHA512, SHA384, or SHA256. Replace digital signature uses with RSA with a key length greater than or equal to 2048-bits, or ECDSA with a key length greater than or equal to 256 bits. -## [CA5358](https://docs.microsoft.com/visualstudio/code-quality/ca5358): Review cipher mode usage with cryptography experts - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5358](https://docs.microsoft.com/visualstudio/code-quality/ca5358): Review cipher mode usage with cryptography experts These cipher modes might be vulnerable to attacks. Consider using recommended modes (CBC, CTS). -## [CA5359](https://docs.microsoft.com/visualstudio/code-quality/ca5359): Do Not Disable Certificate Validation - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5359](https://docs.microsoft.com/visualstudio/code-quality/ca5359): Do Not Disable Certificate Validation A certificate can help authenticate the identity of the server. Clients should validate the server certificate to ensure requests are sent to the intended server. If the ServerCertificateValidationCallback always returns 'true', any certificate will pass validation. -## [CA5360](https://docs.microsoft.com/visualstudio/code-quality/ca5360): Do Not Call Dangerous Methods In Deserialization - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5360](https://docs.microsoft.com/visualstudio/code-quality/ca5360): Do Not Call Dangerous Methods In Deserialization Insecure Deserialization is a vulnerability which occurs when untrusted data is used to abuse the logic of an application, inflict a Denial-of-Service (DoS) attack, or even execute arbitrary code upon it being deserialized. It’s frequently possible for malicious users to abuse these deserialization features when the application is deserializing untrusted data which is under their control. Specifically, invoke dangerous methods in the process of deserialization. Successful insecure deserialization attacks could allow an attacker to carry out attacks such as DoS attacks, authentication bypasses, and remote code execution. -## [CA5361](https://docs.microsoft.com/visualstudio/code-quality/ca5361): Do Not Disable SChannel Use of Strong Crypto - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5361](https://docs.microsoft.com/visualstudio/code-quality/ca5361): Do Not Disable SChannel Use of Strong Crypto Starting with the .NET Framework 4.6, the System.Net.ServicePointManager and System.Net.Security.SslStream classes are recommeded to use new protocols. The old ones have protocol weaknesses and are not supported. Setting Switch.System.Net.DontEnableSchUseStrongCrypto with true will use the old weak crypto check and opt out of the protocol migration. -## [CA5362](https://docs.microsoft.com/visualstudio/code-quality/ca5362): Potential reference cycle in deserialized object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5362](https://docs.microsoft.com/visualstudio/code-quality/ca5362): Potential reference cycle in deserialized object graph Review code that processes untrusted deserialized data for handling of unexpected reference cycles. An unexpected reference cycle should not cause the code to enter an infinite loop. Otherwise, an unexpected reference cycle can allow an attacker to DOS or exhaust the memory of the process when deserializing untrusted data. -## [CA5363](https://docs.microsoft.com/visualstudio/code-quality/ca5363): Do Not Disable Request Validation - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5363](https://docs.microsoft.com/visualstudio/code-quality/ca5363): Do Not Disable Request Validation Request validation is a feature in ASP.NET that examines HTTP requests and determines whether they contain potentially dangerous content. This check adds protection from markup or code in the URL query string, cookies, or posted form values that might have been added for malicious purposes. So, it is generally desirable and should be left enabled for defense in depth. -## [CA5364](https://docs.microsoft.com/visualstudio/code-quality/ca5364): Do Not Use Deprecated Security Protocols - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5364](https://docs.microsoft.com/visualstudio/code-quality/ca5364): Do Not Use Deprecated Security Protocols Using a deprecated security protocol rather than the system default is risky. -## [CA5365](https://docs.microsoft.com/visualstudio/code-quality/ca5365): Do Not Disable HTTP Header Checking - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5365](https://docs.microsoft.com/visualstudio/code-quality/ca5365): Do Not Disable HTTP Header Checking HTTP header checking enables encoding of the carriage return and newline characters, \r and \n, that are found in response headers. This encoding can help to avoid injection attacks that exploit an application that echoes untrusted data contained by the header. -## [CA5366](https://docs.microsoft.com/visualstudio/code-quality/ca5366): Use XmlReader For DataSet Read Xml - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5366](https://docs.microsoft.com/visualstudio/code-quality/ca5366): Use XmlReader For DataSet Read Xml Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5367](https://docs.microsoft.com/visualstudio/code-quality/ca5367): Do Not Serialize Types With Pointer Fields - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5367](https://docs.microsoft.com/visualstudio/code-quality/ca5367): Do Not Serialize Types With Pointer Fields Pointers are not "type safe" in the sense that you cannot guarantee the correctness of the memory they point at. So, serializing types with pointer fields is dangerous, as it may allow an attacker to control the pointer. -## [CA5368](https://docs.microsoft.com/visualstudio/code-quality/ca5368): Set ViewStateUserKey For Classes Derived From Page - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5368](https://docs.microsoft.com/visualstudio/code-quality/ca5368): Set ViewStateUserKey For Classes Derived From Page Setting the ViewStateUserKey property can help you prevent attacks on your application by allowing you to assign an identifier to the view-state variable for individual users so that they cannot use the variable to generate an attack. Otherwise, there will be cross-site request forgery vulnerabilities. -## [CA5369](https://docs.microsoft.com/visualstudio/code-quality/ca5369): Use XmlReader For Deserialize - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5369](https://docs.microsoft.com/visualstudio/code-quality/ca5369): Use XmlReader For Deserialize Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5370](https://docs.microsoft.com/visualstudio/code-quality/ca5370): Use XmlReader For Validating Reader - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5370](https://docs.microsoft.com/visualstudio/code-quality/ca5370): Use XmlReader For Validating Reader Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5371](https://docs.microsoft.com/visualstudio/code-quality/ca5371): Use XmlReader For Schema Read - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5371](https://docs.microsoft.com/visualstudio/code-quality/ca5371): Use XmlReader For Schema Read Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5372](https://docs.microsoft.com/visualstudio/code-quality/ca5372): Use XmlReader For XPathDocument - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5372](https://docs.microsoft.com/visualstudio/code-quality/ca5372): Use XmlReader For XPathDocument Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5373](https://docs.microsoft.com/visualstudio/code-quality/ca5373): Do not use obsolete key derivation function - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5373](https://docs.microsoft.com/visualstudio/code-quality/ca5373): Do not use obsolete key derivation function Password-based key derivation should use PBKDF2 with SHA-2. Avoid using PasswordDeriveBytes since it generates a PBKDF1 key. Avoid using Rfc2898DeriveBytes.CryptDeriveKey since it doesn't use the iteration count or salt. -## [CA5374](https://docs.microsoft.com/visualstudio/code-quality/ca5374): Do Not Use XslTransform - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5374](https://docs.microsoft.com/visualstudio/code-quality/ca5374): Do Not Use XslTransform Do not use XslTransform. It does not restrict potentially dangerous external references. -## [CA5375](https://docs.microsoft.com/visualstudio/code-quality/ca5375): Do Not Use Account Shared Access Signature - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5375](https://docs.microsoft.com/visualstudio/code-quality/ca5375): Do Not Use Account Shared Access Signature Shared Access Signatures(SAS) are a vital part of the security model for any application using Azure Storage, they should provide limited and safe permissions to your storage account to clients that don't have the account key. All of the operations available via a service SAS are also available via an account SAS, that is, account SAS is too powerful. So it is recommended to use Service SAS to delegate access more carefully. -## [CA5376](https://docs.microsoft.com/visualstudio/code-quality/ca5376): Use SharedAccessProtocol HttpsOnly - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5376](https://docs.microsoft.com/visualstudio/code-quality/ca5376): Use SharedAccessProtocol HttpsOnly HTTPS encrypts network traffic. Use HttpsOnly, rather than HttpOrHttps, to ensure network traffic is always encrypted to help prevent disclosure of sensitive data. -## [CA5377](https://docs.microsoft.com/visualstudio/code-quality/ca5377): Use Container Level Access Policy - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5377](https://docs.microsoft.com/visualstudio/code-quality/ca5377): Use Container Level Access Policy No access policy identifier is specified, making tokens non-revocable. -## [CA5378](https://docs.microsoft.com/visualstudio/code-quality/ca5378): Do not disable ServicePointManagerSecurityProtocols - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5378](https://docs.microsoft.com/visualstudio/code-quality/ca5378): Do not disable ServicePointManagerSecurityProtocols Do not set Switch.System.ServiceModel.DisableUsingServicePointManagerSecurityProtocols to true. Setting this switch limits Windows Communication Framework (WCF) to using Transport Layer Security (TLS) 1.0, which is insecure and obsolete. -## [CA5379](https://docs.microsoft.com/visualstudio/code-quality/ca5379): Do Not Use Weak Key Derivation Function Algorithm - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5379](https://docs.microsoft.com/visualstudio/code-quality/ca5379): Do Not Use Weak Key Derivation Function Algorithm Some implementations of the Rfc2898DeriveBytes class allow for a hash algorithm to be specified in a constructor parameter or overwritten in the HashAlgorithm property. If a hash algorithm is specified, then it should be SHA-256 or higher. -## [CA5380](https://docs.microsoft.com/visualstudio/code-quality/ca5380): Do Not Add Certificates To Root Store - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5380](https://docs.microsoft.com/visualstudio/code-quality/ca5380): Do Not Add Certificates To Root Store By default, the Trusted Root Certification Authorities certificate store is configured with a set of public CAs that has met the requirements of the Microsoft Root Certificate Program. Since all trusted root CAs can issue certificates for any domain, an attacker can pick a weak or coercible CA that you install by yourself to target for an attack – and a single vulnerable, malicious or coercible CA undermines the security of the entire system. To make matters worse, these attacks can go unnoticed quite easily. -## [CA5381](https://docs.microsoft.com/visualstudio/code-quality/ca5381): Ensure Certificates Are Not Added To Root Store - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5381](https://docs.microsoft.com/visualstudio/code-quality/ca5381): Ensure Certificates Are Not Added To Root Store By default, the Trusted Root Certification Authorities certificate store is configured with a set of public CAs that has met the requirements of the Microsoft Root Certificate Program. Since all trusted root CAs can issue certificates for any domain, an attacker can pick a weak or coercible CA that you install by yourself to target for an attack – and a single vulnerable, malicious or coercible CA undermines the security of the entire system. To make matters worse, these attacks can go unnoticed quite easily. -## [CA5382](https://docs.microsoft.com/visualstudio/code-quality/ca5382): Use Secure Cookies In ASP.Net Core - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5382](https://docs.microsoft.com/visualstudio/code-quality/ca5382): Use Secure Cookies In ASP.Net Core Applications available over HTTPS must use secure cookies. -## [CA5383](https://docs.microsoft.com/visualstudio/code-quality/ca5383): Ensure Use Secure Cookies In ASP.Net Core - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5383](https://docs.microsoft.com/visualstudio/code-quality/ca5383): Ensure Use Secure Cookies In ASP.Net Core Applications available over HTTPS must use secure cookies. -## [CA5384](https://docs.microsoft.com/visualstudio/code-quality/ca5384): Do Not Use Digital Signature Algorithm (DSA) - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5384](https://docs.microsoft.com/visualstudio/code-quality/ca5384): Do Not Use Digital Signature Algorithm (DSA) DSA is too weak to use. -## [CA5385](https://docs.microsoft.com/visualstudio/code-quality/ca5385): Use Rivest–Shamir–Adleman (RSA) Algorithm With Sufficient Key Size - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5385](https://docs.microsoft.com/visualstudio/code-quality/ca5385): Use Rivest–Shamir–Adleman (RSA) Algorithm With Sufficient Key Size Encryption algorithms are vulnerable to brute force attacks when too small a key size is used. -## [CA5386](https://docs.microsoft.com/visualstudio/code-quality/ca5386): Avoid hardcoding SecurityProtocolType value - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5386](https://docs.microsoft.com/visualstudio/code-quality/ca5386): Avoid hardcoding SecurityProtocolType value Avoid hardcoding SecurityProtocolType {0}, and instead use SecurityProtocolType.SystemDefault to allow the operating system to choose the best Transport Layer Security protocol to use. -## [CA5387](https://docs.microsoft.com/visualstudio/code-quality/ca5387): Do Not Use Weak Key Derivation Function With Insufficient Iteration Count - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5387](https://docs.microsoft.com/visualstudio/code-quality/ca5387): Do Not Use Weak Key Derivation Function With Insufficient Iteration Count When deriving cryptographic keys from user-provided inputs such as password, use sufficient iteration count (at least 100k). -## [CA5388](https://docs.microsoft.com/visualstudio/code-quality/ca5388): Ensure Sufficient Iteration Count When Using Weak Key Derivation Function - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5388](https://docs.microsoft.com/visualstudio/code-quality/ca5388): Ensure Sufficient Iteration Count When Using Weak Key Derivation Function When deriving cryptographic keys from user-provided inputs such as password, use sufficient iteration count (at least 100k). -## [CA5389](https://docs.microsoft.com/visualstudio/code-quality/ca5389): Do Not Add Archive Item's Path To The Target File System Path - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5389](https://docs.microsoft.com/visualstudio/code-quality/ca5389): Do Not Add Archive Item's Path To The Target File System Path When extracting files from an archive and using the archive item's path, check if the path is safe. Archive path can be relative and can lead to file system access outside of the expected file system target path, leading to malicious config changes and remote code execution via lay-and-wait technique. -## [CA5390](https://docs.microsoft.com/visualstudio/code-quality/ca5390): Do not hard-code encryption key - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5390](https://docs.microsoft.com/visualstudio/code-quality/ca5390): Do not hard-code encryption key SymmetricAlgorithm's .Key property, or a method's rgbKey parameter, should never be a hard-coded value. -## [CA5391](https://docs.microsoft.com/visualstudio/code-quality/ca5391): Use antiforgery tokens in ASP.NET Core MVC controllers - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5391](https://docs.microsoft.com/visualstudio/code-quality/ca5391): Use antiforgery tokens in ASP.NET Core MVC controllers Handling a POST, PUT, PATCH, or DELETE request without validating an antiforgery token may be vulnerable to cross-site request forgery attacks. A cross-site request forgery attack can send malicious requests from an authenticated user to your ASP.NET Core MVC controller. -## [CA5392](https://docs.microsoft.com/visualstudio/code-quality/ca5392): Use DefaultDllImportSearchPaths attribute for P/Invokes - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5392](https://docs.microsoft.com/visualstudio/code-quality/ca5392): Use DefaultDllImportSearchPaths attribute for P/Invokes By default, P/Invokes using DllImportAttribute probe a number of directories, including the current working directory for the library to load. This can be a security issue for certain applications, leading to DLL hijacking. -## [CA5393](https://docs.microsoft.com/visualstudio/code-quality/ca5393): Do not use unsafe DllImportSearchPath value - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5393](https://docs.microsoft.com/visualstudio/code-quality/ca5393): Do not use unsafe DllImportSearchPath value There could be a malicious DLL in the default DLL search directories. Or, depending on where your application is run from, there could be a malicious DLL in the application's directory. Use a DllImportSearchPath value that specifies an explicit search path instead. The DllImportSearchPath flags that this rule looks for can be configured in .editorconfig. -## [CA5394](https://docs.microsoft.com/visualstudio/code-quality/ca5394): Do not use insecure randomness - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5394](https://docs.microsoft.com/visualstudio/code-quality/ca5394): Do not use insecure randomness Using a cryptographically weak pseudo-random number generator may allow an attacker to predict what security-sensitive value will be generated. Use a cryptographically strong random number generator if an unpredictable value is required, or ensure that weak pseudo-random numbers aren't used in a security-sensitive manner. -## [CA5395](https://docs.microsoft.com/visualstudio/code-quality/ca5395): Miss HttpVerb attribute for action methods - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5395](https://docs.microsoft.com/visualstudio/code-quality/ca5395): Miss HttpVerb attribute for action methods All the methods that create, edit, delete, or otherwise modify data do so in the [HttpPost] overload of the method, which needs to be protected with the anti forgery attribute from request forgery. Performing a GET operation should be a safe operation that has no side effects and doesn't modify your persisted data. -## [CA5396](https://docs.microsoft.com/visualstudio/code-quality/ca5396): Set HttpOnly to true for HttpCookie - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5396](https://docs.microsoft.com/visualstudio/code-quality/ca5396): Set HttpOnly to true for HttpCookie As a defense in depth measure, ensure security sensitive HTTP cookies are marked as HttpOnly. This indicates web browsers should disallow scripts from accessing the cookies. Injected malicious scripts are a common way of stealing cookies. -## [CA5397](https://docs.microsoft.com/visualstudio/code-quality/ca5397): Do not use deprecated SslProtocols values - |Item|Value| |-|-| |Category|Security| -|Enabled|True| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5397](https://docs.microsoft.com/visualstudio/code-quality/ca5397): Do not use deprecated SslProtocols values Older protocol versions of Transport Layer Security (TLS) are less secure than TLS 1.2 and TLS 1.3, and are more likely to have new vulnerabilities. Avoid older protocol versions to minimize risk. -## [CA5398](https://docs.microsoft.com/visualstudio/code-quality/ca5398): Avoid hardcoded SslProtocols values - |Item|Value| |-|-| |Category|Security| -|Enabled|False| +|Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5398](https://docs.microsoft.com/visualstudio/code-quality/ca5398): Avoid hardcoded SslProtocols values Current Transport Layer Security protocol versions may become deprecated if vulnerabilities are found. Avoid hardcoding SslProtocols values to keep your application secure. Use 'None' to let the Operating System choose a version. -## [CA5399](https://docs.microsoft.com/visualstudio/code-quality/ca5399): HttpClients should enable certificate revocation list checks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5399](https://docs.microsoft.com/visualstudio/code-quality/ca5399): HttpClients should enable certificate revocation list checks Using HttpClient without providing a platform specific handler (WinHttpHandler or CurlHandler or HttpClientHandler) where the CheckCertificateRevocationList property is set to true, will allow revoked certificates to be accepted by the HttpClient as valid. -## [CA5400](https://docs.microsoft.com/visualstudio/code-quality/ca5400): Ensure HttpClient certificate revocation list check is not disabled - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5400](https://docs.microsoft.com/visualstudio/code-quality/ca5400): Ensure HttpClient certificate revocation list check is not disabled Using HttpClient without providing a platform specific handler (WinHttpHandler or CurlHandler or HttpClientHandler) where the CheckCertificateRevocationList property is set to true, will allow revoked certificates to be accepted by the HttpClient as valid. -## [CA5401](https://docs.microsoft.com/visualstudio/code-quality/ca5401): Do not use CreateEncryptor with non-default IV - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5401](https://docs.microsoft.com/visualstudio/code-quality/ca5401): Do not use CreateEncryptor with non-default IV Symmetric encryption should always use a non-repeatable initialization vector to prevent dictionary attacks. -## [CA5402](https://docs.microsoft.com/visualstudio/code-quality/ca5402): Use CreateEncryptor with the default IV - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5402](https://docs.microsoft.com/visualstudio/code-quality/ca5402): Use CreateEncryptor with the default IV Symmetric encryption should always use a non-repeatable initialization vector to prevent dictionary attacks. -## [CA5403](https://docs.microsoft.com/visualstudio/code-quality/ca5403): Do not hard-code certificate - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5403](https://docs.microsoft.com/visualstudio/code-quality/ca5403): Do not hard-code certificate Hard-coded certificates in source code are vulnerable to being exploited. -## [IL3000](https://docs.microsoft.com/visualstudio/code-quality/il3000): Avoid using accessing Assembly file path when publishing as a single-file - |Item|Value| |-|-| -|Category|Publish| -|Enabled|True| +|Category|Security| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [IL3000](https://docs.microsoft.com/visualstudio/code-quality/il3000): Avoid using accessing Assembly file path when publishing as a single-file '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. -## [IL3001](https://docs.microsoft.com/visualstudio/code-quality/il3001): Avoid using accessing Assembly file path when publishing as a single-file - |Item|Value| |-|-| |Category|Publish| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [IL3001](https://docs.microsoft.com/visualstudio/code-quality/il3001): Avoid using accessing Assembly file path when publishing as a single-file '{0}' will throw for assemblies embedded in a single-file app +|Item|Value| +|-|-| +|Category|Publish| +|Enabled|True| +|Severity|Warning| +|CodeFix|False| +--- diff --git a/src/Microsoft.NetCore.Analyzers/RulesMissingDocumentation.md b/src/Microsoft.NetCore.Analyzers/RulesMissingDocumentation.md index 4126869a38..dedfab7d66 100644 --- a/src/Microsoft.NetCore.Analyzers/RulesMissingDocumentation.md +++ b/src/Microsoft.NetCore.Analyzers/RulesMissingDocumentation.md @@ -1,6 +1,5 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| CA1416 | https://docs.microsoft.com/visualstudio/code-quality/ca1416 | Validate platform compatibility | -CA1834 | https://docs.microsoft.com/visualstudio/code-quality/ca1834 | Consider using 'StringBuilder.Append(char)' when applicable | diff --git a/src/Microsoft.NetFramework.Analyzers/Microsoft.NetFramework.Analyzers.md b/src/Microsoft.NetFramework.Analyzers/Microsoft.NetFramework.Analyzers.md index 884efe6d34..9765dfedf2 100644 --- a/src/Microsoft.NetFramework.Analyzers/Microsoft.NetFramework.Analyzers.md +++ b/src/Microsoft.NetFramework.Analyzers/Microsoft.NetFramework.Analyzers.md @@ -2,79 +2,72 @@ ## [CA1058](https://docs.microsoft.com/visualstudio/code-quality/ca1058): Types should not extend certain base types +An externally visible type extends certain base types. Use one of the alternatives. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -An externally visible type extends certain base types. Use one of the alternatives. +--- ## [CA2153](https://docs.microsoft.com/visualstudio/code-quality/ca2153): Do Not Catch Corrupted State Exceptions +Catching corrupted state exceptions could mask errors (such as access violations), resulting in inconsistent state of execution or making it easier for attackers to compromise system. Instead, catch and handle a more specific set of exception type(s) or re-throw the exception. + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Catching corrupted state exceptions could mask errors (such as access violations), resulting in inconsistent state of execution or making it easier for attackers to compromise system. Instead, catch and handle a more specific set of exception type(s) or re-throw the exception. +--- ## [CA3075](https://docs.microsoft.com/visualstudio/code-quality/ca3075): Insecure DTD processing in XML +Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when invoking XmlReader.Create(), setting the InnerXml property of the XmlDocument and enabling DTD processing using XmlUrlResolver insecurely can lead to information disclosure. Replace it with a call to the Load() method overload that takes an XmlReader instance, use XmlReader.Create() to accept XmlReaderSettings arguments or consider explicitly setting secure values. The DataViewSettingCollectionString property of DataViewManager should always be assigned from a trusted source, the DtdProcessing property should be set to false, and the XmlResolver property should be changed to XmlSecureResolver or null. + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when invoking XmlReader.Create(), setting the InnerXml property of the XmlDocument and enabling DTD processing using XmlUrlResolver insecurely can lead to information disclosure. Replace it with a call to the Load() method overload that takes an XmlReader instance, use XmlReader.Create() to accept XmlReaderSettings arguments or consider explicitly setting secure values. The DataViewSettingCollectionString property of DataViewManager should always be assigned from a trusted source, the DtdProcessing property should be set to false, and the XmlResolver property should be changed to XmlSecureResolver or null.  +--- ## [CA3076](https://docs.microsoft.com/visualstudio/code-quality/ca3076): Insecure XSLT script processing. +Providing an insecure XsltSettings instance and an insecure XmlResolver instance to XslCompiledTransform.Load method is potentially unsafe as it allows processing script within XSL, which on an untrusted XSL input may lead to malicious code execution. Either replace the insecure XsltSettings argument with XsltSettings.Default or an instance that has disabled document function and script execution, or replace the XmlResolver argurment with null or an XmlSecureResolver instance. This message may be suppressed if the input is known to be from a trusted source and external resource resolution from locations that are not known in advance must be supported. + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Providing an insecure XsltSettings instance and an insecure XmlResolver instance to XslCompiledTransform.Load method is potentially unsafe as it allows processing script within XSL, which on an untrusted XSL input may lead to malicious code execution. Either replace the insecure XsltSettings argument with XsltSettings.Default or an instance that has disabled document function and script execution, or replace the XmlResolver argurment with null or an XmlSecureResolver instance. This message may be suppressed if the input is known to be from a trusted source and external resource resolution from locations that are not known in advance must be supported. +--- ## [CA3077](https://docs.microsoft.com/visualstudio/code-quality/ca3077): Insecure Processing in API Design, XmlDocument and XmlTextReader +Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocument and using XmlUrlResolver for resolving external XML entities may lead to information disclosure. Ensure to set the XmlResolver property to null, create an instance of XmlSecureResolver when processing untrusted input, or use XmlReader.Create method with a secure XmlReaderSettings argument. Unless you need to enable it, ensure the DtdProcessing property is set to false. + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocument and using XmlUrlResolver for resolving external XML entities may lead to information disclosure. Ensure to set the XmlResolver property to null, create an instance of XmlSecureResolver when processing untrusted input, or use XmlReader.Create method with a secure XmlReaderSettings argument. Unless you need to enable it, ensure the DtdProcessing property is set to false.  +--- ## [CA3147](https://docs.microsoft.com/visualstudio/code-quality/ca3147): Mark Verb Handlers With Validate Antiforgery Token +Missing ValidateAntiForgeryTokenAttribute on controller action {0} + |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Missing ValidateAntiForgeryTokenAttribute on controller action {0} - +--- diff --git a/src/Microsoft.NetFramework.Analyzers/RulesMissingDocumentation.md b/src/Microsoft.NetFramework.Analyzers/RulesMissingDocumentation.md index 8add8039c5..75e0f77588 100644 --- a/src/Microsoft.NetFramework.Analyzers/RulesMissingDocumentation.md +++ b/src/Microsoft.NetFramework.Analyzers/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md b/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md index c87a844f7a..b7bcb6f140 100644 --- a/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md +++ b/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md @@ -2,577 +2,535 @@ ## [CA1000](https://docs.microsoft.com/visualstudio/code-quality/ca1000): Do not declare static members on generic types +When a static member of a generic type is called, the type argument must be specified for the type. When a generic instance member that does not support inference is called, the type argument must be specified for the member. In these two cases, the syntax for specifying the type argument is different and easily confused. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -When a static member of a generic type is called, the type argument must be specified for the type. When a generic instance member that does not support inference is called, the type argument must be specified for the member. In these two cases, the syntax for specifying the type argument is different and easily confused. +--- ## [CA1001](https://docs.microsoft.com/visualstudio/code-quality/ca1001): Types that own disposable fields should be disposable +A class declares and implements an instance field that is a System.IDisposable type, and the class does not implement IDisposable. A class that declares an IDisposable field indirectly owns an unmanaged resource and should implement the IDisposable interface. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Hidden| |CodeFix|True| - -### Rule description - -A class declares and implements an instance field that is a System.IDisposable type, and the class does not implement IDisposable. A class that declares an IDisposable field indirectly owns an unmanaged resource and should implement the IDisposable interface. +--- ## [CA1002](https://docs.microsoft.com/visualstudio/code-quality/ca1002): Do not expose generic lists +System.Collections.Generic.List\ is a generic collection that's designed for performance and not inheritance. List\ does not contain virtual members that make it easier to change the behavior of an inherited class. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -System.Collections.Generic.List is a generic collection that's designed for performance and not inheritance. List does not contain virtual members that make it easier to change the behavior of an inherited class. +--- ## [CA1003](https://docs.microsoft.com/visualstudio/code-quality/ca1003): Use generic event handler instances +A type contains an event that declares an EventHandler delegate that returns void, whose signature contains two parameters (the first an object and the second a type that is assignable to EventArgs), and the containing assembly targets Microsoft .NET Framework?2.0. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A type contains an event that declares an EventHandler delegate that returns void, whose signature contains two parameters (the first an object and the second a type that is assignable to EventArgs), and the containing assembly targets Microsoft .NET Framework?2.0. +--- ## [CA1005](https://docs.microsoft.com/visualstudio/code-quality/ca1005): Avoid excessive parameters on generic types +The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. +--- ## [CA1008](https://docs.microsoft.com/visualstudio/code-quality/ca1008): Enums should have zero value +The default value of an uninitialized enumeration, just as other value types, is zero. A nonflags-attributed enumeration should define a member by using the value of zero so that the default value is a valid value of the enumeration. If an enumeration that has the FlagsAttribute attribute applied defines a zero-valued member, its name should be ""None"" to indicate that no values have been set in the enumeration. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -The default value of an uninitialized enumeration, just as other value types, is zero. A nonflags-attributed enumeration should define a member by using the value of zero so that the default value is a valid value of the enumeration. If an enumeration that has the FlagsAttribute attribute applied defines a zero-valued member, its name should be ""None"" to indicate that no values have been set in the enumeration. +--- ## [CA1010](https://docs.microsoft.com/visualstudio/code-quality/ca1010): Generic interface should also be implemented +To broaden the usability of a type, implement one of the generic interfaces. This is especially true for collections as they can then be used to populate generic collection types. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -To broaden the usability of a type, implement one of the generic interfaces. This is especially true for collections as they can then be used to populate generic collection types. +--- ## [CA1012](https://docs.microsoft.com/visualstudio/code-quality/ca1012): Abstract types should not have public constructors +Constructors on abstract types can be called only by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type that has a public constructor is incorrectly designed. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Constructors on abstract types can be called only by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type that has a public constructor is incorrectly designed. +--- ## [CA1014](https://docs.microsoft.com/visualstudio/code-quality/ca1014): Mark assemblies with CLSCompliant +The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages. Good design dictates that all assemblies explicitly indicate CLS compliance by using CLSCompliantAttribute . If this attribute is not present on an assembly, the assembly is not compliant. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages. Good design dictates that all assemblies explicitly indicate CLS compliance by using CLSCompliantAttribute . If this attribute is not present on an assembly, the assembly is not compliant. +--- ## [CA1016](https://docs.microsoft.com/visualstudio/code-quality/ca1016): Mark assemblies with assembly version +The .NET Framework uses the version number to uniquely identify an assembly, and to bind to types in strongly named assemblies. The version number is used together with version and publisher policy. By default, applications run only with the assembly version with which they were built. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -The .NET Framework uses the version number to uniquely identify an assembly, and to bind to types in strongly named assemblies. The version number is used together with version and publisher policy. By default, applications run only with the assembly version with which they were built. +--- ## [CA1017](https://docs.microsoft.com/visualstudio/code-quality/ca1017): Mark assemblies with ComVisible +ComVisibleAttribute determines how COM clients access managed code. Good design dictates that assemblies explicitly indicate COM visibility. COM visibility can be set for the whole assembly and then overridden for individual types and type members. If this attribute is not present, the contents of the assembly are visible to COM clients. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -ComVisibleAttribute determines how COM clients access managed code. Good design dictates that assemblies explicitly indicate COM visibility. COM visibility can be set for the whole assembly and then overridden for individual types and type members. If this attribute is not present, the contents of the assembly are visible to COM clients. +--- ## [CA1018](https://docs.microsoft.com/visualstudio/code-quality/ca1018): Mark attributes with AttributeUsageAttribute +Specify AttributeUsage on {0} + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -Specify AttributeUsage on {0} +--- ## [CA1019](https://docs.microsoft.com/visualstudio/code-quality/ca1019): Define accessors for attribute arguments +Remove the property setter from {0} or reduce its accessibility because it corresponds to positional argument {1} + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Remove the property setter from {0} or reduce its accessibility because it corresponds to positional argument {1} +--- ## [CA1021](https://docs.microsoft.com/visualstudio/code-quality/ca1021): Avoid out parameters +Passing types by reference (using 'out' or 'ref') requires experience with pointers, understanding how value types and reference types differ, and handling methods with multiple return values. Also, the difference between 'out' and 'ref' parameters is not widely understood. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Passing types by reference (using 'out' or 'ref') requires experience with pointers, understanding how value types and reference types differ, and handling methods with multiple return values. Also, the difference between 'out' and 'ref' parameters is not widely understood. +--- ## [CA1024](https://docs.microsoft.com/visualstudio/code-quality/ca1024): Use properties where appropriate +A public or protected method has a name that starts with ""Get"", takes no parameters, and returns a value that is not an array. The method might be a good candidate to become a property. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A public or protected method has a name that starts with ""Get"", takes no parameters, and returns a value that is not an array. The method might be a good candidate to become a property. +--- ## [CA1027](https://docs.microsoft.com/visualstudio/code-quality/ca1027): Mark enums with FlagsAttribute +An enumeration is a value type that defines a set of related named constants. Apply FlagsAttribute to an enumeration when its named constants can be meaningfully combined. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An enumeration is a value type that defines a set of related named constants. Apply FlagsAttribute to an enumeration when its named constants can be meaningfully combined. +--- ## [CA1028](https://docs.microsoft.com/visualstudio/code-quality/ca1028): Enum Storage should be Int32 +An enumeration is a value type that defines a set of related named constants. By default, the System.Int32 data type is used to store the constant value. Although you can change this underlying type, it is not required or recommended for most scenarios. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An enumeration is a value type that defines a set of related named constants. By default, the System.Int32 data type is used to store the constant value. Although you can change this underlying type, it is not required or recommended for most scenarios. +--- ## [CA1030](https://docs.microsoft.com/visualstudio/code-quality/ca1030): Use events where appropriate +This rule detects methods that have names that ordinarily would be used for events. If a method is called in response to a clearly defined state change, the method should be invoked by an event handler. Objects that call the method should raise events instead of calling the method directly. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -This rule detects methods that have names that ordinarily would be used for events. If a method is called in response to a clearly defined state change, the method should be invoked by an event handler. Objects that call the method should raise events instead of calling the method directly. +--- ## [CA1031](https://docs.microsoft.com/visualstudio/code-quality/ca1031): Do not catch general exception types +A general exception such as System.Exception or System.SystemException or a disallowed exception type is caught in a catch statement, or a general catch clause is used. General and disallowed exceptions should not be caught. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A general exception such as System.Exception or System.SystemException or a disallowed exception type is caught in a catch statement, or a general catch clause is used. General and disallowed exceptions should not be caught. +--- ## [CA1032](https://docs.microsoft.com/visualstudio/code-quality/ca1032): Implement standard exception constructors +Failure to provide the full set of constructors can make it difficult to correctly handle exceptions. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Failure to provide the full set of constructors can make it difficult to correctly handle exceptions. +--- ## [CA1033](https://docs.microsoft.com/visualstudio/code-quality/ca1033): Interface methods should be callable by child types +An unsealed externally visible type provides an explicit method implementation of a public interface and does not provide an alternative externally visible method that has the same name. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An unsealed externally visible type provides an explicit method implementation of a public interface and does not provide an alternative externally visible method that has the same name. +--- ## [CA1034](https://docs.microsoft.com/visualstudio/code-quality/ca1034): Nested types should not be visible +A nested type is a type that is declared in the scope of another type. Nested types are useful to encapsulate private implementation details of the containing type. Used for this purpose, nested types should not be externally visible. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A nested type is a type that is declared in the scope of another type. Nested types are useful to encapsulate private implementation details of the containing type. Used for this purpose, nested types should not be externally visible. +--- ## [CA1036](https://docs.microsoft.com/visualstudio/code-quality/ca1036): Override methods on comparable types +A public or protected type implements the System.IComparable interface. It does not override Object.Equals nor does it overload the language-specific operator for equality, inequality, less than, less than or equal, greater than or greater than or equal. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Hidden| |CodeFix|True| - -### Rule description - -A public or protected type implements the System.IComparable interface. It does not override Object.Equals nor does it overload the language-specific operator for equality, inequality, less than, less than or equal, greater than or greater than or equal. +--- ## [CA1040](https://docs.microsoft.com/visualstudio/code-quality/ca1040): Avoid empty interfaces +Interfaces define members that provide a behavior or usage contract. The functionality that is described by the interface can be adopted by any type, regardless of where the type appears in the inheritance hierarchy. A type implements an interface by providing implementations for the members of the interface. An empty interface does not define any members; therefore, it does not define a contract that can be implemented. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Interfaces define members that provide a behavior or usage contract. The functionality that is described by the interface can be adopted by any type, regardless of where the type appears in the inheritance hierarchy. A type implements an interface by providing implementations for the members of the interface. An empty interface does not define any members; therefore, it does not define a contract that can be implemented. +--- ## [CA1041](https://docs.microsoft.com/visualstudio/code-quality/ca1041): Provide ObsoleteAttribute message +A type or member is marked by using a System.ObsoleteAttribute attribute that does not have its ObsoleteAttribute.Message property specified. When a type or member that is marked by using ObsoleteAttribute is compiled, the Message property of the attribute is displayed. This gives the user information about the obsolete type or member. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -A type or member is marked by using a System.ObsoleteAttribute attribute that does not have its ObsoleteAttribute.Message property specified. When a type or member that is marked by using ObsoleteAttribute is compiled, the Message property of the attribute is displayed. This gives the user information about the obsolete type or member. +--- ## [CA1043](https://docs.microsoft.com/visualstudio/code-quality/ca1043): Use Integral Or String Argument For Indexers -|Item|Value| -|-|-| -|Category|Design| -|Enabled|False| -|Severity|Warning| -|CodeFix|False| - -### Rule description - Indexers, that is, indexed properties, should use integer or string types for the index. These types are typically used for indexing data structures and increase the usability of the library. Use of the Object type should be restricted to those cases where the specific integer or string type cannot be specified at design time. If the design requires other types for the index, reconsider whether the type represents a logical data store. If it does not represent a logical data store, use a method. -## [CA1044](https://docs.microsoft.com/visualstudio/code-quality/ca1044): Properties should not be write only - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1044](https://docs.microsoft.com/visualstudio/code-quality/ca1044): Properties should not be write only Although it is acceptable and often necessary to have a read-only property, the design guidelines prohibit the use of write-only properties. This is because letting a user set a value, and then preventing the user from viewing that value, does not provide any security. Also, without read access, the state of shared objects cannot be viewed, which limits their usefulness. -## [CA1045](https://docs.microsoft.com/visualstudio/code-quality/ca1045): Do not pass types by reference - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1045](https://docs.microsoft.com/visualstudio/code-quality/ca1045): Do not pass types by reference Passing types by reference (using out or ref) requires experience with pointers, understanding how value types and reference types differ, and handling methods that have multiple return values. Also, the difference between out and ref parameters is not widely understood. -## [CA1046](https://docs.microsoft.com/visualstudio/code-quality/ca1046): Do not overload equality operator on reference types - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1046](https://docs.microsoft.com/visualstudio/code-quality/ca1046): Do not overload equality operator on reference types For reference types, the default implementation of the equality operator is almost always correct. By default, two references are equal only if they point to the same object. If the operator is providing meaningful value equality, the type should implement the generic 'System.IEquatable' interface. -## [CA1047](https://docs.microsoft.com/visualstudio/code-quality/ca1047): Do not declare protected member in sealed type - |Item|Value| |-|-| |Category|Design| -|Enabled|True| -|Severity|Info| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1047](https://docs.microsoft.com/visualstudio/code-quality/ca1047): Do not declare protected member in sealed type Types declare protected members so that inheriting types can access or override the member. By definition, you cannot inherit from a sealed type, which means that protected methods on sealed types cannot be called. -## [CA1050](https://docs.microsoft.com/visualstudio/code-quality/ca1050): Declare types in namespaces - |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| +--- -### Rule description +## [CA1050](https://docs.microsoft.com/visualstudio/code-quality/ca1050): Declare types in namespaces Types are declared in namespaces to prevent name collisions and as a way to organize related types in an object hierarchy. -## [CA1051](https://docs.microsoft.com/visualstudio/code-quality/ca1051): Do not declare visible instance fields - |Item|Value| |-|-| |Category|Design| |Enabled|True| -|Severity|Hidden| +|Severity|Info| |CodeFix|False| +--- -### Rule description +## [CA1051](https://docs.microsoft.com/visualstudio/code-quality/ca1051): Do not declare visible instance fields The primary use of a field should be as an implementation detail. Fields should be private or internal and should be exposed by using properties. -## [CA1052](https://docs.microsoft.com/visualstudio/code-quality/ca1052): Static holder types should be Static or NotInheritable - |Item|Value| |-|-| |Category|Design| -|Enabled|False| -|Severity|Warning| -|CodeFix|True| +|Enabled|True| +|Severity|Hidden| +|CodeFix|False| +--- -### Rule description +## [CA1052](https://docs.microsoft.com/visualstudio/code-quality/ca1052): Static holder types should be Static or NotInheritable Type '{0}' is a static holder type but is neither static nor NotInheritable -## [CA1054](https://docs.microsoft.com/visualstudio/code-quality/ca1054): URI-like parameters should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1054](https://docs.microsoft.com/visualstudio/code-quality/ca1054): URI-like parameters should not be strings This rule assumes that the parameter represents a Uniform Resource Identifier (URI). A string representation or a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. 'System.Uri' class provides these services in a safe and secure manner. -## [CA1055](https://docs.microsoft.com/visualstudio/code-quality/ca1055): URI-like return values should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [CA1055](https://docs.microsoft.com/visualstudio/code-quality/ca1055): URI-like return values should not be strings This rule assumes that the method returns a URI. A string representation of a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. The System.Uri class provides these services in a safe and secure manner. -## [CA1056](https://docs.microsoft.com/visualstudio/code-quality/ca1056): URI-like properties should not be strings - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1056](https://docs.microsoft.com/visualstudio/code-quality/ca1056): URI-like properties should not be strings This rule assumes that the property represents a Uniform Resource Identifier (URI). A string representation of a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. The System.Uri class provides these services in a safe and secure manner. -## [CA1058](https://docs.microsoft.com/visualstudio/code-quality/ca1058): Types should not extend certain base types - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1058](https://docs.microsoft.com/visualstudio/code-quality/ca1058): Types should not extend certain base types An externally visible type extends certain base types. Use one of the alternatives. -## [CA1060](https://docs.microsoft.com/visualstudio/code-quality/ca1060): Move pinvokes to native methods class - |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1060](https://docs.microsoft.com/visualstudio/code-quality/ca1060): Move pinvokes to native methods class Platform Invocation methods, such as those that are marked by using the System.Runtime.InteropServices.DllImportAttribute attribute, or methods that are defined by using the Declare keyword in Visual Basic, access unmanaged code. These methods should be of the NativeMethods, SafeNativeMethods, or UnsafeNativeMethods class. +|Item|Value| +|-|-| +|Category|Design| +|Enabled|False| +|Severity|Warning| +|CodeFix|False| +--- + ## [CA1061](https://docs.microsoft.com/visualstudio/code-quality/ca1061): Do not hide base class methods +A method in a base type is hidden by an identically named method in a derived type when the parameter signature of the derived method differs only by types that are more weakly derived than the corresponding types in the parameter signature of the base method. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -A method in a base type is hidden by an identically named method in a derived type when the parameter signature of the derived method differs only by types that are more weakly derived than the corresponding types in the parameter signature of the base method. +--- ## [CA1062](https://docs.microsoft.com/visualstudio/code-quality/ca1062): Validate arguments of public methods +An externally visible method dereferences one of its reference arguments without verifying whether that argument is null (Nothing in Visual Basic). All reference arguments that are passed to externally visible methods should be checked against null. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. If the method is designed to be called only by known assemblies, you should make the method internal. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -An externally visible method dereferences one of its reference arguments without verifying whether that argument is null (Nothing in Visual Basic). All reference arguments that are passed to externally visible methods should be checked against null. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. If the method is designed to be called only by known assemblies, you should make the method internal. +--- ## [CA1063](https://docs.microsoft.com/visualstudio/code-quality/ca1063): Implement IDisposable Correctly +All IDisposable types should implement the Dispose pattern correctly. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -All IDisposable types should implement the Dispose pattern correctly. +--- ## [CA1064](https://docs.microsoft.com/visualstudio/code-quality/ca1064): Exceptions should be public +An internal exception is visible only inside its own internal scope. After the exception falls outside the internal scope, only the base exception can be used to catch the exception. If the internal exception is inherited from T:System.Exception, T:System.SystemException, or T:System.ApplicationException, the external code will not have sufficient information to know what to do with the exception. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An internal exception is visible only inside its own internal scope. After the exception falls outside the internal scope, only the base exception can be used to catch the exception. If the internal exception is inherited from T:System.Exception, T:System.SystemException, or T:System.ApplicationException, the external code will not have sufficient information to know what to do with the exception. +--- ## [CA1065](https://docs.microsoft.com/visualstudio/code-quality/ca1065): Do not raise exceptions in unexpected locations +A method that is not expected to throw exceptions throws an exception. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A method that is not expected to throw exceptions throws an exception. +--- ## [CA1066](https://docs.microsoft.com/visualstudio/code-quality/ca1066): Implement IEquatable when overriding Object.Equals +When a type T overrides Object.Equals(object), the implementation must cast the object argument to the correct type T before performing the comparison. If the type implements IEquatable\, and therefore offers the method T.Equals(T), and if the argument is known at compile time to be of type T, then the compiler can call IEquatable\.Equals(T) instead of Object.Equals(object), and no cast is necessary, improving performance. + |Item|Value| |-|-| |Category|Design| |Enabled|False| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1067](https://docs.microsoft.com/visualstudio/code-quality/ca1067): Override Object.Equals(object) when implementing IEquatable\ -When a type T overrides Object.Equals(object), the implementation must cast the object argument to the correct type T before performing the comparison. If the type implements IEquatable, and therefore offers the method T.Equals(T), and if the argument is known at compile time to be of type T, then the compiler can call IEquatable.Equals(T) instead of Object.Equals(object), and no cast is necessary, improving performance. - -## [CA1067](https://docs.microsoft.com/visualstudio/code-quality/ca1067): Override Object.Equals(object) when implementing IEquatable +When a type T implements the interface IEquatable\, it suggests to a user who sees a call to the Equals method in source code that an instance of the type can be equated with an instance of any other type. The user might be confused if their attempt to equate the type with an instance of another type fails to compile. This violates the "principle of least surprise". |Item|Value| |-|-| @@ -580,805 +538,731 @@ When a type T overrides Object.Equals(object), the implementation must cast the |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -When a type T implements the interface IEquatable, it suggests to a user who sees a call to the Equals method in source code that an instance of the type can be equated with an instance of any other type. The user might be confused if their attempt to equate the type with an instance of another type fails to compile. This violates the "principle of least surprise". +--- ## [CA1068](https://docs.microsoft.com/visualstudio/code-quality/ca1068): CancellationToken parameters must come last +Method '{0}' should take CancellationToken as the last parameter + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -Method '{0}' should take CancellationToken as the last parameter +--- ## [CA1069](https://docs.microsoft.com/visualstudio/code-quality/ca1069): Enums values should not be duplicated +The field reference '{0}' is duplicated in this bitwise initialization + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -The field reference '{0}' is duplicated in this bitwise initialization +--- ## [CA1070](https://docs.microsoft.com/visualstudio/code-quality/ca1070): Do not declare event fields as virtual +Do not declare virtual events in a base class. Overridden events in a derived class have undefined behavior. The C# compiler does not handle this correctly and it is unpredictable whether a subscriber to the derived event will actually be subscribing to the base class event. + |Item|Value| |-|-| |Category|Design| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -Do not declare virtual events in a base class. Overridden events in a derived class have undefined behavior. The C# compiler does not handle this correctly and it is unpredictable whether a subscriber to the derived event will actually be subscribing to the base class event. +--- ## [CA1200](https://docs.microsoft.com/visualstudio/code-quality/ca1200): Avoid using cref tags with a prefix +Use of cref tags with prefixes should be avoided, since it prevents the compiler from verifying references and the IDE from updating references during refactorings. It is permissible to suppress this error at a single documentation site if the cref must use a prefix because the type being mentioned is not findable by the compiler. For example, if a cref is mentioning a special attribute in the full framework but you're in a file that compiles against the portable framework, or if you want to reference a type at higher layer of Roslyn, you should suppress the error. You should not suppress the error just because you want to take a shortcut and avoid using the full syntax. + |Item|Value| |-|-| |Category|Documentation| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -Use of cref tags with prefixes should be avoided, since it prevents the compiler from verifying references and the IDE from updating references during refactorings. It is permissible to suppress this error at a single documentation site if the cref must use a prefix because the type being mentioned is not findable by the compiler. For example, if a cref is mentioning a special attribute in the full framework but you're in a file that compiles against the portable framework, or if you want to reference a type at higher layer of Roslyn, you should suppress the error. You should not suppress the error just because you want to take a shortcut and avoid using the full syntax. +--- ## [CA1303](https://docs.microsoft.com/visualstudio/code-quality/ca1303): Do not pass literals as localized parameters +A method passes a string literal as a parameter to a constructor or method in the .NET Framework class library and that string should be localizable. To fix a violation of this rule, replace the string literal with a string retrieved through an instance of the ResourceManager class. + |Item|Value| |-|-| |Category|Globalization| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A method passes a string literal as a parameter to a constructor or method in the .NET Framework class library and that string should be localizable. To fix a violation of this rule, replace the string literal with a string retrieved through an instance of the ResourceManager class. +--- ## [CA1304](https://docs.microsoft.com/visualstudio/code-quality/ca1304): Specify CultureInfo +A method or constructor calls a member that has an overload that accepts a System.Globalization.CultureInfo parameter, and the method or constructor does not call the overload that takes the CultureInfo parameter. When a CultureInfo or System.IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'CultureInfo' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -A method or constructor calls a member that has an overload that accepts a System.Globalization.CultureInfo parameter, and the method or constructor does not call the overload that takes the CultureInfo parameter. When a CultureInfo or System.IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'CultureInfo' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'. +--- ## [CA1305](https://docs.microsoft.com/visualstudio/code-quality/ca1305): Specify IFormatProvider +A method or constructor calls one or more members that have overloads that accept a System.IFormatProvider parameter, and the method or constructor does not call the overload that takes the IFormatProvider parameter. When a System.Globalization.CultureInfo or IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be based on the input from/output displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider'. Otherwise, if the result will be stored and accessed by software, such as when it is loaded from disk/database and when it is persisted to disk/database, specify 'CultureInfo.InvariantCulture'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -A method or constructor calls one or more members that have overloads that accept a System.IFormatProvider parameter, and the method or constructor does not call the overload that takes the IFormatProvider parameter. When a System.Globalization.CultureInfo or IFormatProvider object is not supplied, the default value that is supplied by the overloaded member might not have the effect that you want in all locales. If the result will be based on the input from/output displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider'. Otherwise, if the result will be stored and accessed by software, such as when it is loaded from disk/database and when it is persisted to disk/database, specify 'CultureInfo.InvariantCulture'. +--- ## [CA1307](https://docs.microsoft.com/visualstudio/code-quality/ca1307): Specify StringComparison for clarity +A string comparison operation uses a method overload that does not set a StringComparison parameter. It is recommended to use the overload with StringComparison parameter for clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A string comparison operation uses a method overload that does not set a StringComparison parameter. It is recommended to use the overload with StringComparison parameter for clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. +--- ## [CA1308](https://docs.microsoft.com/visualstudio/code-quality/ca1308): Normalize strings to uppercase +Strings should be normalized to uppercase. A small group of characters cannot make a round trip when they are converted to lowercase. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters. + |Item|Value| |-|-| |Category|Globalization| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Strings should be normalized to uppercase. A small group of characters cannot make a round trip when they are converted to lowercase. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters. +--- ## [CA1309](https://docs.microsoft.com/visualstudio/code-quality/ca1309): Use ordinal string comparison +A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Hidden| |CodeFix|True| - -### Rule description - -A string comparison operation that is nonlinguistic does not set the StringComparison parameter to either Ordinal or OrdinalIgnoreCase. By explicitly setting the parameter to either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, becomes more correct, and becomes more reliable. +--- ## [CA1310](https://docs.microsoft.com/visualstudio/code-quality/ca1310): Specify StringComparison for correctness +A string comparison operation uses a method overload that does not set a StringComparison parameter, hence its behavior could vary based on the current user's locale settings. It is strongly recommended to use the overload with StringComparison parameter for correctness and clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -A string comparison operation uses a method overload that does not set a StringComparison parameter, hence its behavior could vary based on the current user's locale settings. It is strongly recommended to use the overload with StringComparison parameter for correctness and clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'. +--- ## [CA1401](https://docs.microsoft.com/visualstudio/code-quality/ca1401): P/Invokes should not be visible +A public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic). Such methods should not be exposed. + |Item|Value| |-|-| |Category|Interoperability| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -A public or protected method in a public type has the System.Runtime.InteropServices.DllImportAttribute attribute (also implemented by the Declare keyword in Visual Basic). Such methods should not be exposed. +--- ## [CA1416](https://docs.microsoft.com/visualstudio/code-quality/ca1416): Validate platform compatibility +Using platform dependent API on a component makes the code no longer work across all platforms. + |Item|Value| |-|-| |Category|Interoperability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Using platform dependent API on a component makes the code no longer work across all platforms. +--- ## [CA1417](https://docs.microsoft.com/visualstudio/code-quality/ca1417): Do not use 'OutAttribute' on string parameters for P/Invokes +String parameters passed by value with the 'OutAttribute' can destabilize the runtime if the string is an interned string. + |Item|Value| |-|-| |Category|Interoperability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -String parameters passed by value with the 'OutAttribute' can destabilize the runtime if the string is an interned string. +--- ## [CA1501](https://docs.microsoft.com/visualstudio/code-quality/ca1501): Avoid excessive inheritance +Deeply nested type hierarchies can be difficult to follow, understand, and maintain. This rule limits analysis to hierarchies in the same module. To fix a violation of this rule, derive the type from a base type that is less deep in the inheritance hierarchy or eliminate some of the intermediate base types. + |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Deeply nested type hierarchies can be difficult to follow, understand, and maintain. This rule limits analysis to hierarchies in the same module. To fix a violation of this rule, derive the type from a base type that is less deep in the inheritance hierarchy or eliminate some of the intermediate base types. +--- ## [CA1502](https://docs.microsoft.com/visualstudio/code-quality/ca1502): Avoid excessive complexity +Cyclomatic complexity measures the number of linearly independent paths through the method, which is determined by the number and complexity of conditional branches. A low cyclomatic complexity generally indicates a method that is easy to understand, test, and maintain. The cyclomatic complexity is calculated from a control flow graph of the method and is given as follows: `cyclomatic complexity = the number of edges - the number of nodes + 1`, where a node represents a logic branch point and an edge represents a line between nodes. + |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Cyclomatic complexity measures the number of linearly independent paths through the method, which is determined by the number and complexity of conditional branches. A low cyclomatic complexity generally indicates a method that is easy to understand, test, and maintain. The cyclomatic complexity is calculated from a control flow graph of the method and is given as follows: `cyclomatic complexity = the number of edges - the number of nodes + 1`, where a node represents a logic branch point and an edge represents a line between nodes. +--- ## [CA1505](https://docs.microsoft.com/visualstudio/code-quality/ca1505): Avoid unmaintainable code +The maintainability index is calculated by using the following metrics: lines of code, program volume, and cyclomatic complexity. Program volume is a measure of the difficulty of understanding of a symbol that is based on the number of operators and operands in the code. Cyclomatic complexity is a measure of the structural complexity of the type or method. A low maintainability index indicates that code is probably difficult to maintain and would be a good candidate to redesign. + |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The maintainability index is calculated by using the following metrics: lines of code, program volume, and cyclomatic complexity. Program volume is a measure of the difficulty of understanding of a symbol that is based on the number of operators and operands in the code. Cyclomatic complexity is a measure of the structural complexity of the type or method. A low maintainability index indicates that code is probably difficult to maintain and would be a good candidate to redesign. +--- ## [CA1506](https://docs.microsoft.com/visualstudio/code-quality/ca1506): Avoid excessive class coupling +This rule measures class coupling by counting the number of unique type references that a symbol contains. Symbols that have a high degree of class coupling can be difficult to maintain. It is a good practice to have types and methods that exhibit low coupling and high cohesion. To fix this violation, try to redesign the code to reduce the number of types to which it is coupled. + |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -This rule measures class coupling by counting the number of unique type references that a symbol contains. Symbols that have a high degree of class coupling can be difficult to maintain. It is a good practice to have types and methods that exhibit low coupling and high cohesion. To fix this violation, try to redesign the code to reduce the number of types to which it is coupled. +--- ## [CA1507](https://docs.microsoft.com/visualstudio/code-quality/ca1507): Use nameof to express symbol names +Using nameof helps keep your code valid when refactoring. + |Item|Value| |-|-| |Category|Maintainability| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -Using nameof helps keep your code valid when refactoring. +--- ## [CA1508](https://docs.microsoft.com/visualstudio/code-quality/ca1508): Avoid dead conditional code -|Item|Value| -|-|-| -|Category|Maintainability| -|Enabled|False| -|Severity|Warning| -|CodeFix|False| - -### Rule description - '{0}' is never '{1}'. Remove or refactor the condition(s) to avoid dead code. -## [CA1509](https://docs.microsoft.com/visualstudio/code-quality/ca1509): Invalid entry in code metrics rule specification file - |Item|Value| |-|-| |Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1509](https://docs.microsoft.com/visualstudio/code-quality/ca1509): Invalid entry in code metrics rule specification file Invalid entry in code metrics rule specification file. -## [CA1700](https://docs.microsoft.com/visualstudio/code-quality/ca1700): Do not name enum values 'Reserved' - |Item|Value| |-|-| -|Category|Naming| +|Category|Maintainability| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change. +## [CA1700](https://docs.microsoft.com/visualstudio/code-quality/ca1700): Do not name enum values 'Reserved' -## [CA1707](https://docs.microsoft.com/visualstudio/code-quality/ca1707): Identifiers should not contain underscores +This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change. |Item|Value| |-|-| |Category|Naming| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1707](https://docs.microsoft.com/visualstudio/code-quality/ca1707): Identifiers should not contain underscores By convention, identifier names do not contain the underscore (_) character. This rule checks namespaces, types, members, and parameters. -## [CA1708](https://docs.microsoft.com/visualstudio/code-quality/ca1708): Identifiers should differ by more than case - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1708](https://docs.microsoft.com/visualstudio/code-quality/ca1708): Identifiers should differ by more than case Identifiers for namespaces, types, members, and parameters cannot differ only by case because languages that target the common language runtime are not required to be case-sensitive. -## [CA1710](https://docs.microsoft.com/visualstudio/code-quality/ca1710): Identifiers should have correct suffix - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1710](https://docs.microsoft.com/visualstudio/code-quality/ca1710): Identifiers should have correct suffix By convention, the names of types that extend certain base types or that implement certain interfaces, or types that are derived from these types, have a suffix that is associated with the base type or interface. -## [CA1711](https://docs.microsoft.com/visualstudio/code-quality/ca1711): Identifiers should not have incorrect suffix - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1711](https://docs.microsoft.com/visualstudio/code-quality/ca1711): Identifiers should not have incorrect suffix By convention, only the names of types that extend certain base types or that implement certain interfaces, or types that are derived from these types, should end with specific reserved suffixes. Other type names should not use these reserved suffixes. -## [CA1712](https://docs.microsoft.com/visualstudio/code-quality/ca1712): Do not prefix enum values with type name - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1712](https://docs.microsoft.com/visualstudio/code-quality/ca1712): Do not prefix enum values with type name An enumeration's values should not start with the type name of the enumeration. -## [CA1713](https://docs.microsoft.com/visualstudio/code-quality/ca1713): Events should not have 'Before' or 'After' prefix - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1713](https://docs.microsoft.com/visualstudio/code-quality/ca1713): Events should not have 'Before' or 'After' prefix Event names should describe the action that raises the event. To name related events that are raised in a specific sequence, use the present or past tense to indicate the relative position in the sequence of actions. For example, when naming a pair of events that is raised when closing a resource, you might name it 'Closing' and 'Closed', instead of 'BeforeClose' and 'AfterClose'. -## [CA1715](https://docs.microsoft.com/visualstudio/code-quality/ca1715): Identifiers should have correct prefix - |Item|Value| |-|-| |Category|Naming| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1715](https://docs.microsoft.com/visualstudio/code-quality/ca1715): Identifiers should have correct prefix The name of an externally visible interface does not start with an uppercase ""I"". The name of a generic type parameter on an externally visible type or method does not start with an uppercase ""T"". -## [CA1716](https://docs.microsoft.com/visualstudio/code-quality/ca1716): Identifiers should not match keywords - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1716](https://docs.microsoft.com/visualstudio/code-quality/ca1716): Identifiers should not match keywords A namespace name or a type name matches a reserved keyword in a programming language. Identifiers for namespaces and types should not match keywords that are defined by languages that target the common language runtime. -## [CA1720](https://docs.microsoft.com/visualstudio/code-quality/ca1720): Identifier contains type name - |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1720](https://docs.microsoft.com/visualstudio/code-quality/ca1720): Identifier contains type name Names of parameters and members are better used to communicate their meaning than to describe their type, which is expected to be provided by development tools. For names of members, if a data type name must be used, use a language-independent name instead of a language-specific one. -## [CA1721](https://docs.microsoft.com/visualstudio/code-quality/ca1721): Property names should not match get methods - |Item|Value| |-|-| |Category|Naming| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA1721](https://docs.microsoft.com/visualstudio/code-quality/ca1721): Property names should not match get methods The name of a public or protected member starts with ""Get"" and otherwise matches the name of a public or protected property. ""Get"" methods and properties should have names that clearly distinguish their function. -## [CA1724](https://docs.microsoft.com/visualstudio/code-quality/ca1724): Type names should not match namespaces - |Item|Value| |-|-| |Category|Naming| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA1724](https://docs.microsoft.com/visualstudio/code-quality/ca1724): Type names should not match namespaces Type names should not match the names of namespaces that are defined in the .NET Framework class library. Violating this rule can reduce the usability of the library. +|Item|Value| +|-|-| +|Category|Naming| +|Enabled|False| +|Severity|Warning| +|CodeFix|False| +--- + ## [CA1725](https://docs.microsoft.com/visualstudio/code-quality/ca1725): Parameter names should match base declaration +Consistent naming of parameters in an override hierarchy increases the usability of the method overrides. A parameter name in a derived method that differs from the name in the base declaration can cause confusion about whether the method is an override of the base method or a new overload of the method. + |Item|Value| |-|-| |Category|Naming| |Enabled|True| |Severity|Hidden| |CodeFix|True| - -### Rule description - -Consistent naming of parameters in an override hierarchy increases the usability of the method overrides. A parameter name in a derived method that differs from the name in the base declaration can cause confusion about whether the method is an override of the base method or a new overload of the method. +--- ## [CA1801](https://docs.microsoft.com/visualstudio/code-quality/ca1801): Review unused parameters +Avoid unused paramereters in your code. If the parameter cannot be removed, then change its name so it starts with an underscore and is optionally followed by an integer, such as '_', '_1', '_2', etc. These are treated as special discard symbol names. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Avoid unused paramereters in your code. If the parameter cannot be removed, then change its name so it starts with an underscore and is optionally followed by an integer, such as '_', '_1', '_2', etc. These are treated as special discard symbol names. +--- ## [CA1802](https://docs.microsoft.com/visualstudio/code-quality/ca1802): Use literals where appropriate +A field is declared static and read-only (Shared and ReadOnly in Visual Basic), and is initialized by using a value that is computable at compile time. Because the value that is assigned to the targeted field is computable at compile time, change the declaration to a const (Const in Visual Basic) field so that the value is computed at compile time instead of at run?time. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -A field is declared static and read-only (Shared and ReadOnly in Visual Basic), and is initialized by using a value that is computable at compile time. Because the value that is assigned to the targeted field is computable at compile time, change the declaration to a const (Const in Visual Basic) field so that the value is computed at compile time instead of at run?time. +--- ## [CA1805](https://docs.microsoft.com/visualstudio/code-quality/ca1805): Do not initialize unnecessarily +The .NET runtime initializes all fields of reference types to their default values before running the constructor. In most cases, explicitly initializing a field to its default value in a constructor is redundant, adding maintenance costs and potentially degrading performance (such as with increased assembly size), and the explicit initialization can be removed. In some cases, such as with static readonly fields that permanently retain their default value, consider instead changing them to be constants or properties. + |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -The .NET runtime initializes all fields of reference types to their default values before running the constructor. In most cases, explicitly initializing a field to its default value in a constructor is redundant, adding maintenance costs and potentially degrading performance (such as with increased assembly size), and the explicit initialization can be removed. In some cases, such as with static readonly fields that permanently retain their default value, consider instead changing them to be constants or properties. +--- ## [CA1806](https://docs.microsoft.com/visualstudio/code-quality/ca1806): Do not ignore method results +A new object is created but never used; or a method that creates and returns a new string is called and the new string is never used; or a COM or P/Invoke method returns an HRESULT or error code that is never used. + |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -A new object is created but never used; or a method that creates and returns a new string is called and the new string is never used; or a COM or P/Invoke method returns an HRESULT or error code that is never used. +--- ## [CA1810](https://docs.microsoft.com/visualstudio/code-quality/ca1810): Initialize reference type static fields inline +A reference type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A reference type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. +--- ## [CA1812](https://docs.microsoft.com/visualstudio/code-quality/ca1812): Avoid uninstantiated internal classes +An instance of an assembly-level type is not created by code in the assembly. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -An instance of an assembly-level type is not created by code in the assembly. +--- ## [CA1813](https://docs.microsoft.com/visualstudio/code-quality/ca1813): Avoid unsealed attributes +The .NET Framework class library provides methods for retrieving custom attributes. By default, these methods search the attribute inheritance hierarchy. Sealing the attribute eliminates the search through the inheritance hierarchy and can improve performance. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -The .NET Framework class library provides methods for retrieving custom attributes. By default, these methods search the attribute inheritance hierarchy. Sealing the attribute eliminates the search through the inheritance hierarchy and can improve performance. +--- ## [CA1814](https://docs.microsoft.com/visualstudio/code-quality/ca1814): Prefer jagged arrays over multidimensional +A jagged array is an array whose elements are arrays. The arrays that make up the elements can be of different sizes, leading to less wasted space for some sets of data. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A jagged array is an array whose elements are arrays. The arrays that make up the elements can be of different sizes, leading to less wasted space for some sets of data. +--- ## [CA1815](https://docs.microsoft.com/visualstudio/code-quality/ca1815): Override equals and operator equals on value types +For value types, the inherited implementation of Equals uses the Reflection library and compares the contents of all fields. Reflection is computationally expensive, and comparing every field for equality might be unnecessary. If you expect users to compare or sort instances, or to use instances as hash table keys, your value type should implement Equals. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -For value types, the inherited implementation of Equals uses the Reflection library and compares the contents of all fields. Reflection is computationally expensive, and comparing every field for equality might be unnecessary. If you expect users to compare or sort instances, or to use instances as hash table keys, your value type should implement Equals. +--- ## [CA1816](https://docs.microsoft.com/visualstudio/code-quality/ca1816): Dispose methods should call SuppressFinalize +A method that is an implementation of Dispose does not call GC.SuppressFinalize; or a method that is not an implementation of Dispose calls GC.SuppressFinalize; or a method calls GC.SuppressFinalize and passes something other than this (Me in Visual?Basic). + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -A method that is an implementation of Dispose does not call GC.SuppressFinalize; or a method that is not an implementation of Dispose calls GC.SuppressFinalize; or a method calls GC.SuppressFinalize and passes something other than this (Me in Visual?Basic). +--- ## [CA1819](https://docs.microsoft.com/visualstudio/code-quality/ca1819): Properties should not return arrays +Arrays that are returned by properties are not write-protected, even when the property is read-only. To keep the array tamper-proof, the property must return a copy of the array. Typically, users will not understand the adverse performance implications of calling such a property. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Arrays that are returned by properties are not write-protected, even when the property is read-only. To keep the array tamper-proof, the property must return a copy of the array. Typically, users will not understand the adverse performance implications of calling such a property. +--- ## [CA1820](https://docs.microsoft.com/visualstudio/code-quality/ca1820): Test for empty strings using string length +Comparing strings by using the String.Length property or the String.IsNullOrEmpty method is significantly faster than using Equals. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Comparing strings by using the String.Length property or the String.IsNullOrEmpty method is significantly faster than using Equals. +--- ## [CA1821](https://docs.microsoft.com/visualstudio/code-quality/ca1821): Remove empty Finalizers +Finalizers should be avoided where possible, to avoid the additional performance overhead involved in tracking object lifetime. + |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -Finalizers should be avoided where possible, to avoid the additional performance overhead involved in tracking object lifetime. +--- ## [CA1822](https://docs.microsoft.com/visualstudio/code-quality/ca1822): Mark members as static +Members that do not access instance data or call instance methods can be marked as static. After you mark the methods as static, the compiler will emit nonvirtual call sites to these members. This can give you a measurable performance gain for performance-sensitive code. + |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -Members that do not access instance data or call instance methods can be marked as static. After you mark the methods as static, the compiler will emit nonvirtual call sites to these members. This can give you a measurable performance gain for performance-sensitive code. +--- ## [CA1823](https://docs.microsoft.com/visualstudio/code-quality/ca1823): Avoid unused private fields +Private fields were detected that do not appear to be accessed in the assembly. + |Item|Value| |-|-| |Category|Performance| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Private fields were detected that do not appear to be accessed in the assembly. +--- ## [CA1824](https://docs.microsoft.com/visualstudio/code-quality/ca1824): Mark assemblies with NeutralResourcesLanguageAttribute -|Item|Value| -|-|-| -|Category|Performance| -|Enabled|True| -|Severity|Info| -|CodeFix|False| - -### Rule description - The NeutralResourcesLanguage attribute informs the ResourceManager of the language that was used to display the resources of a neutral culture for an assembly. This improves lookup performance for the first resource that you load and can reduce your working set. -## [CA1825](https://docs.microsoft.com/visualstudio/code-quality/ca1825): Avoid zero-length array allocations - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [CA1825](https://docs.microsoft.com/visualstudio/code-quality/ca1825): Avoid zero-length array allocations Avoid unnecessary zero-length array allocations. Use {0} instead. -## [CA1826](https://docs.microsoft.com/visualstudio/code-quality/ca1826): Do not use Enumerable methods on indexable collections - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1826](https://docs.microsoft.com/visualstudio/code-quality/ca1826): Do not use Enumerable methods on indexable collections This collection is directly indexable. Going through LINQ here causes unnecessary allocations and CPU work. -## [CA1827](https://docs.microsoft.com/visualstudio/code-quality/ca1827): Do not use Count() or LongCount() when Any() can be used - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1827](https://docs.microsoft.com/visualstudio/code-quality/ca1827): Do not use Count() or LongCount() when Any() can be used For non-empty collections, Count() and LongCount() enumerate the entire sequence, while Any() stops at the first item or the first item that satisfies a condition. -## [CA1828](https://docs.microsoft.com/visualstudio/code-quality/ca1828): Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1828](https://docs.microsoft.com/visualstudio/code-quality/ca1828): Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used For non-empty collections, CountAsync() and LongCountAsync() enumerate the entire sequence, while AnyAsync() stops at the first item or the first item that satisfies a condition. -## [CA1829](https://docs.microsoft.com/visualstudio/code-quality/ca1829): Use Length/Count property instead of Count() when available - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1829](https://docs.microsoft.com/visualstudio/code-quality/ca1829): Use Length/Count property instead of Count() when available Enumerable.Count() potentially enumerates the sequence while a Length/Count property is a direct access. -## [CA1830](https://docs.microsoft.com/visualstudio/code-quality/ca1830): Prefer strongly-typed Append and Insert method overloads on StringBuilder - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1830](https://docs.microsoft.com/visualstudio/code-quality/ca1830): Prefer strongly-typed Append and Insert method overloads on StringBuilder StringBuilder.Append and StringBuilder.Insert provide overloads for multiple types beyond System.String. When possible, prefer the strongly-typed overloads over using ToString() and the string-based overload. -## [CA1831](https://docs.microsoft.com/visualstudio/code-quality/ca1831): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| -|Severity|Warning| +|Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1831](https://docs.microsoft.com/visualstudio/code-quality/ca1831): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on string values produces a copy of requested portion of the string. This copy is usually unnecessary when it is implicitly used as a ReadOnlySpan or ReadOnlyMemory value. Use the AsSpan method to avoid the unnecessary copy. -## [CA1832](https://docs.microsoft.com/visualstudio/code-quality/ca1832): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| -|Severity|Info| +|Severity|Warning| |CodeFix|True| +--- -### Rule description +## [CA1832](https://docs.microsoft.com/visualstudio/code-quality/ca1832): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on array values produces a copy of requested portion of the array. This copy is usually unnecessary when it is implicitly used as a ReadOnlySpan or ReadOnlyMemory value. Use the AsSpan method to avoid the unnecessary copy. -## [CA1833](https://docs.microsoft.com/visualstudio/code-quality/ca1833): Use AsSpan or AsMemory instead of Range-based indexers when appropriate - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1833](https://docs.microsoft.com/visualstudio/code-quality/ca1833): Use AsSpan or AsMemory instead of Range-based indexers when appropriate The Range-based indexer on array values produces a copy of requested portion of the array. This copy is often unwanted when it is implicitly used as a Span or Memory value. Use the AsSpan method to avoid the copy. -## [CA1834](https://docs.microsoft.com/visualstudio/code-quality/ca1834): Consider using 'StringBuilder.Append(char)' when applicable - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1834](https://docs.microsoft.com/visualstudio/code-quality/ca1834): Consider using 'StringBuilder.Append(char)' when applicable 'StringBuilder.Append(char)' is more efficient than 'StringBuilder.Append(string)' when the string is a single character. When calling 'Append' with a constant, prefer using a constant char rather than a constant string containing one character. -## [CA1835](https://docs.microsoft.com/visualstudio/code-quality/ca1835): Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description - -'Stream' has a 'ReadAsync' overload that takes a 'Memory' as the first argument, and a 'WriteAsync' overload that takes a 'ReadOnlyMemory' as the first argument. Prefer calling the memory based overloads, which are more efficient. +## [CA1835](https://docs.microsoft.com/visualstudio/code-quality/ca1835): Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' -## [CA1836](https://docs.microsoft.com/visualstudio/code-quality/ca1836): Prefer IsEmpty over Count +'Stream' has a 'ReadAsync' overload that takes a 'Memory\' as the first argument, and a 'WriteAsync' overload that takes a 'ReadOnlyMemory\' as the first argument. Prefer calling the memory based overloads, which are more efficient. |Item|Value| |-|-| @@ -1386,155 +1270,155 @@ The Range-based indexer on array values produces a copy of requested portion of |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1836](https://docs.microsoft.com/visualstudio/code-quality/ca1836): Prefer IsEmpty over Count For determining whether the object contains or not any items, prefer using 'IsEmpty' property rather than retrieving the number of items from the 'Count' property and comparing it to 0 or 1. -## [CA1837](https://docs.microsoft.com/visualstudio/code-quality/ca1837): Use 'Environment.ProcessId' - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|True| +--- -### Rule description +## [CA1837](https://docs.microsoft.com/visualstudio/code-quality/ca1837): Use 'Environment.ProcessId' 'Environment.ProcessId' is simpler and faster than 'Process.GetCurrentProcess().Id'. +|Item|Value| +|-|-| +|Category|Performance| +|Enabled|True| +|Severity|Info| +|CodeFix|True| +--- + ## [CA1838](https://docs.microsoft.com/visualstudio/code-quality/ca1838): Avoid 'StringBuilder' parameters for P/Invokes +Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. + |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -Marshalling of 'StringBuilder' always creates a native buffer copy, resulting in multiple allocations for one marshalling operation. +--- ## [CA2000](https://docs.microsoft.com/visualstudio/code-quality/ca2000): Dispose objects before losing scope +If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead. + |Item|Value| |-|-| |Category|Reliability| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead. +--- ## [CA2002](https://docs.microsoft.com/visualstudio/code-quality/ca2002): Do not lock on objects with weak identity +An object is said to have a weak identity when it can be directly accessed across application domain boundaries. A thread that tries to acquire a lock on an object that has a weak identity can be blocked by a second thread in a different application domain that has a lock on the same object. + |Item|Value| |-|-| |Category|Reliability| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -An object is said to have a weak identity when it can be directly accessed across application domain boundaries. A thread that tries to acquire a lock on an object that has a weak identity can be blocked by a second thread in a different application domain that has a lock on the same object. +--- ## [CA2007](https://docs.microsoft.com/visualstudio/code-quality/ca2007): Consider calling ConfigureAwait on the awaited task +When an asynchronous method awaits a Task directly, continuation occurs in the same thread that created the task. Consider calling Task.ConfigureAwait(Boolean) to signal your intention for continuation. Call ConfigureAwait(false) on the task to schedule continuations to the thread pool, thereby avoiding a deadlock on the UI thread. Passing false is a good option for app-independent libraries. Calling ConfigureAwait(true) on the task has the same behavior as not explicitly calling ConfigureAwait. By explicitly calling this method, you're letting readers know you intentionally want to perform the continuation on the original synchronization context. + |Item|Value| |-|-| |Category|Reliability| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -When an asynchronous method awaits a Task directly, continuation occurs in the same thread that created the task. Consider calling Task.ConfigureAwait(Boolean) to signal your intention for continuation. Call ConfigureAwait(false) on the task to schedule continuations to the thread pool, thereby avoiding a deadlock on the UI thread. Passing false is a good option for app-independent libraries. Calling ConfigureAwait(true) on the task has the same behavior as not explicitly calling ConfigureAwait. By explicitly calling this method, you're letting readers know you intentionally want to perform the continuation on the original synchronization context. +--- ## [CA2008](https://docs.microsoft.com/visualstudio/code-quality/ca2008): Do not create tasks without passing a TaskScheduler +Do not create tasks unless you are using one of the overloads that takes a TaskScheduler. The default is to schedule on TaskScheduler.Current, which would lead to deadlocks. Either use TaskScheduler.Default to schedule on the thread pool, or explicitly pass TaskScheduler.Current to make your intentions clear. + |Item|Value| |-|-| |Category|Reliability| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Do not create tasks unless you are using one of the overloads that takes a TaskScheduler. The default is to schedule on TaskScheduler.Current, which would lead to deadlocks. Either use TaskScheduler.Default to schedule on the thread pool, or explicitly pass TaskScheduler.Current to make your intentions clear. +--- ## [CA2009](https://docs.microsoft.com/visualstudio/code-quality/ca2009): Do not call ToImmutableCollection on an ImmutableCollection value +Do not call {0} on an {1} value + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -Do not call {0} on an {1} value +--- ## [CA2011](https://docs.microsoft.com/visualstudio/code-quality/ca2011): Avoid infinite recursion +Do not assign the property within its setter. This call might result in an infinite recursion. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -Do not assign the property within its setter. This call might result in an infinite recursion. +--- ## [CA2012](https://docs.microsoft.com/visualstudio/code-quality/ca2012): Use ValueTasks correctly +ValueTasks returned from member invocations are intended to be directly awaited. Attempts to consume a ValueTask multiple times or to directly access one's result before it's known to be completed may result in an exception or corruption. Ignoring such a ValueTask is likely an indication of a functional bug and may degrade performance. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -ValueTasks returned from member invocations are intended to be directly awaited. Attempts to consume a ValueTask multiple times or to directly access one's result before it's known to be completed may result in an exception or corruption. Ignoring such a ValueTask is likely an indication of a functional bug and may degrade performance. +--- ## [CA2013](https://docs.microsoft.com/visualstudio/code-quality/ca2013): Do not use ReferenceEquals with value types +Value type typed arguments are uniquely boxed for each call to this method, therefore the result is always false. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Value type typed arguments are uniquely boxed for each call to this method, therefore the result is always false. +--- ## [CA2014](https://docs.microsoft.com/visualstudio/code-quality/ca2014): Do not use stackalloc in loops +Stack space allocated by a stackalloc is only released at the end of the current method's invocation. Using it in a loop can result in unbounded stack growth and eventual stack overflow conditions. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description - -Stack space allocated by a stackalloc is only released at the end of the current method's invocation. Using it in a loop can result in unbounded stack growth and eventual stack overflow conditions. +## [CA2015](https://docs.microsoft.com/visualstudio/code-quality/ca2015): Do not define finalizers for types derived from MemoryManager\ -## [CA2015](https://docs.microsoft.com/visualstudio/code-quality/ca2015): Do not define finalizers for types derived from MemoryManager +Adding a finalizer to a type derived from MemoryManager\ may permit memory to be freed while it is still in use by a Span\. |Item|Value| |-|-| @@ -1542,974 +1426,887 @@ Stack space allocated by a stackalloc is only released at the end of the current |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Adding a finalizer to a type derived from MemoryManager may permit memory to be freed while it is still in use by a Span. +--- ## [CA2016](https://docs.microsoft.com/visualstudio/code-quality/ca2016): Forward the 'CancellationToken' parameter to methods that take one +Forward the 'CancellationToken' parameter to methods that take one to ensure the operation cancellation notifications gets properly propagated, or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token. + |Item|Value| |-|-| |Category|Reliability| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -Forward the 'CancellationToken' parameter to methods that take one to ensure the operation cancellation notifications gets properly propagated, or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token. +--- ## [CA2100](https://docs.microsoft.com/visualstudio/code-quality/ca2100): Review SQL queries for security vulnerabilities +SQL queries that directly use user input can be vulnerable to SQL injection attacks. Review this SQL query for potential vulnerabilities, and consider using a parameterized SQL query. + |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -SQL queries that directly use user input can be vulnerable to SQL injection attacks. Review this SQL query for potential vulnerabilities, and consider using a parameterized SQL query. +--- ## [CA2101](https://docs.microsoft.com/visualstudio/code-quality/ca2101): Specify marshaling for P/Invoke string arguments +A platform invoke member allows partially trusted callers, has a string parameter, and does not explicitly marshal the string. This can cause a potential security vulnerability. + |Item|Value| |-|-| |Category|Globalization| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -A platform invoke member allows partially trusted callers, has a string parameter, and does not explicitly marshal the string. This can cause a potential security vulnerability. +--- ## [CA2109](https://docs.microsoft.com/visualstudio/code-quality/ca2109): Review visible event handlers +A public or protected event-handling method was detected. Event-handling methods should not be exposed unless absolutely necessary. + |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A public or protected event-handling method was detected. Event-handling methods should not be exposed unless absolutely necessary. +--- ## [CA2119](https://docs.microsoft.com/visualstudio/code-quality/ca2119): Seal methods that satisfy private interfaces +An inheritable public type provides an overridable method implementation of an internal (Friend in Visual Basic) interface. To fix a violation of this rule, prevent the method from being overridden outside the assembly. + |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An inheritable public type provides an overridable method implementation of an internal (Friend in Visual Basic) interface. To fix a violation of this rule, prevent the method from being overridden outside the assembly. +--- ## [CA2153](https://docs.microsoft.com/visualstudio/code-quality/ca2153): Do Not Catch Corrupted State Exceptions +Catching corrupted state exceptions could mask errors (such as access violations), resulting in inconsistent state of execution or making it easier for attackers to compromise system. Instead, catch and handle a more specific set of exception type(s) or re-throw the exception. + |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Catching corrupted state exceptions could mask errors (such as access violations), resulting in inconsistent state of execution or making it easier for attackers to compromise system. Instead, catch and handle a more specific set of exception type(s) or re-throw the exception. +--- ## [CA2200](https://docs.microsoft.com/visualstudio/code-quality/ca2200): Rethrow to preserve stack details +Re-throwing caught exception changes stack information + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Re-throwing caught exception changes stack information +--- ## [CA2201](https://docs.microsoft.com/visualstudio/code-quality/ca2201): Do not raise reserved exception types +An exception of type that is not sufficiently specific or reserved by the runtime should never be raised by user code. This makes the original error difficult to detect and debug. If this exception instance might be thrown, use a different exception type. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Hidden| |CodeFix|False| - -### Rule description - -An exception of type that is not sufficiently specific or reserved by the runtime should never be raised by user code. This makes the original error difficult to detect and debug. If this exception instance might be thrown, use a different exception type. +--- ## [CA2207](https://docs.microsoft.com/visualstudio/code-quality/ca2207): Initialize value type static fields inline +A value type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A value type declares an explicit static constructor. To fix a violation of this rule, initialize all static data when it is declared and remove the static constructor. +--- ## [CA2208](https://docs.microsoft.com/visualstudio/code-quality/ca2208): Instantiate argument exceptions correctly +A call is made to the default (parameterless) constructor of an exception type that is or derives from ArgumentException, or an incorrect string argument is passed to a parameterized constructor of an exception type that is or derives from ArgumentException. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -A call is made to the default (parameterless) constructor of an exception type that is or derives from ArgumentException, or an incorrect string argument is passed to a parameterized constructor of an exception type that is or derives from ArgumentException. +--- ## [CA2211](https://docs.microsoft.com/visualstudio/code-quality/ca2211): Non-constant fields should not be visible +Static fields that are neither constants nor read-only are not thread-safe. Access to such a field must be carefully controlled and requires advanced programming techniques to synchronize access to the class object. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -Static fields that are neither constants nor read-only are not thread-safe. Access to such a field must be carefully controlled and requires advanced programming techniques to synchronize access to the class object. +--- ## [CA2213](https://docs.microsoft.com/visualstudio/code-quality/ca2213): Disposable fields should be disposed +A type that implements System.IDisposable declares fields that are of types that also implement IDisposable. The Dispose method of the field is not called by the Dispose method of the declaring type. To fix a violation of this rule, call Dispose on fields that are of types that implement IDisposable if you are responsible for allocating and releasing the unmanaged resources held by the field. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A type that implements System.IDisposable declares fields that are of types that also implement IDisposable. The Dispose method of the field is not called by the Dispose method of the declaring type. To fix a violation of this rule, call Dispose on fields that are of types that implement IDisposable if you are responsible for allocating and releasing the unmanaged resources held by the field. +--- ## [CA2214](https://docs.microsoft.com/visualstudio/code-quality/ca2214): Do not call overridable methods in constructors +Virtual methods defined on the class should not be called from constructors. If a derived class has overridden the method, the derived class version will be called (before the derived class constructor is called). + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -Virtual methods defined on the class should not be called from constructors. If a derived class has overridden the method, the derived class version will be called (before the derived class constructor is called). +--- ## [CA2215](https://docs.microsoft.com/visualstudio/code-quality/ca2215): Dispose methods should call base class dispose +A type that implements System.IDisposable inherits from a type that also implements IDisposable. The Dispose method of the inheriting type does not call the Dispose method of the parent type. To fix a violation of this rule, call base.Dispose in your Dispose method. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Hidden| |CodeFix|True| - -### Rule description - -A type that implements System.IDisposable inherits from a type that also implements IDisposable. The Dispose method of the inheriting type does not call the Dispose method of the parent type. To fix a violation of this rule, call base.Dispose in your Dispose method. +--- ## [CA2216](https://docs.microsoft.com/visualstudio/code-quality/ca2216): Disposable types should declare finalizer +A type that implements System.IDisposable and has fields that suggest the use of unmanaged resources does not implement a finalizer, as described by Object.Finalize. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A type that implements System.IDisposable and has fields that suggest the use of unmanaged resources does not implement a finalizer, as described by Object.Finalize. +--- ## [CA2217](https://docs.microsoft.com/visualstudio/code-quality/ca2217): Do not mark enums with FlagsAttribute +An externally visible enumeration is marked by using FlagsAttribute, and it has one or more values that are not powers of two or a combination of the other defined values on the enumeration. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An externally visible enumeration is marked by using FlagsAttribute, and it has one or more values that are not powers of two or a combination of the other defined values on the enumeration. +--- ## [CA2218](https://docs.microsoft.com/visualstudio/code-quality/ca2218): Override GetHashCode on overriding Equals +GetHashCode returns a value, based on the current instance, that is suited for hashing algorithms and data structures such as a hash table. Two objects that are the same type and are equal must return the same hash code. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -GetHashCode returns a value, based on the current instance, that is suited for hashing algorithms and data structures such as a hash table. Two objects that are the same type and are equal must return the same hash code. +--- ## [CA2219](https://docs.microsoft.com/visualstudio/code-quality/ca2219): Do not raise exceptions in finally clauses +When an exception is raised in a finally clause, the new exception hides the active exception. This makes the original error difficult to detect and debug. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -When an exception is raised in a finally clause, the new exception hides the active exception. This makes the original error difficult to detect and debug. +--- ## [CA2224](https://docs.microsoft.com/visualstudio/code-quality/ca2224): Override Equals on overloading operator equals +A public type implements the equality operator but does not override Object.Equals. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -A public type implements the equality operator but does not override Object.Equals. +--- ## [CA2225](https://docs.microsoft.com/visualstudio/code-quality/ca2225): Operator overloads have named alternates +An operator overload was detected, and the expected named alternative method was not found. The named alternative member provides access to the same functionality as the operator and is provided for developers who program in languages that do not support overloaded operators. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An operator overload was detected, and the expected named alternative method was not found. The named alternative member provides access to the same functionality as the operator and is provided for developers who program in languages that do not support overloaded operators. +--- ## [CA2226](https://docs.microsoft.com/visualstudio/code-quality/ca2226): Operators should have symmetrical overloads +A type implements the equality or inequality operator and does not implement the opposite operator. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -A type implements the equality or inequality operator and does not implement the opposite operator. +--- ## [CA2227](https://docs.microsoft.com/visualstudio/code-quality/ca2227): Collection properties should be read only +A writable collection property allows a user to replace the collection with a different collection. A read-only property stops the collection from being replaced but still allows the individual members to be set. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A writable collection property allows a user to replace the collection with a different collection. A read-only property stops the collection from being replaced but still allows the individual members to be set. +--- ## [CA2229](https://docs.microsoft.com/visualstudio/code-quality/ca2229): Implement serialization constructors +To fix a violation of this rule, implement the serialization constructor. For a sealed class, make the constructor private; otherwise, make it protected. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Hidden| |CodeFix|True| - -### Rule description - -To fix a violation of this rule, implement the serialization constructor. For a sealed class, make the constructor private; otherwise, make it protected. +--- ## [CA2231](https://docs.microsoft.com/visualstudio/code-quality/ca2231): Overload operator equals on overriding value type Equals +In most programming languages there is no default implementation of the equality operator (==) for value types. If your programming language supports operator overloads, you should consider implementing the equality operator. Its behavior should be identical to that of Equals. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -In most programming languages there is no default implementation of the equality operator (==) for value types. If your programming language supports operator overloads, you should consider implementing the equality operator. Its behavior should be identical to that of Equals. +--- ## [CA2234](https://docs.microsoft.com/visualstudio/code-quality/ca2234): Pass system uri objects instead of strings +A call is made to a method that has a string parameter whose name contains "uri", "URI", "urn", "URN", "url", or "URL". The declaring type of the method contains a corresponding method overload that has a System.Uri parameter. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -A call is made to a method that has a string parameter whose name contains "uri", "URI", "urn", "URN", "url", or "URL". The declaring type of the method contains a corresponding method overload that has a System.Uri parameter. +--- ## [CA2235](https://docs.microsoft.com/visualstudio/code-quality/ca2235): Mark all non-serializable fields +An instance field of a type that is not serializable is declared in a type that is serializable. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -An instance field of a type that is not serializable is declared in a type that is serializable. +--- ## [CA2237](https://docs.microsoft.com/visualstudio/code-quality/ca2237): Mark ISerializable types with serializable +To be recognized by the common language runtime as serializable, types must be marked by using the SerializableAttribute attribute even when the type uses a custom serialization routine through implementation of the ISerializable interface. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -To be recognized by the common language runtime as serializable, types must be marked by using the SerializableAttribute attribute even when the type uses a custom serialization routine through implementation of the ISerializable interface. +--- ## [CA2241](https://docs.microsoft.com/visualstudio/code-quality/ca2241): Provide correct arguments to formatting methods +The format argument that is passed to System.String.Format does not contain a format item that corresponds to each object argument, or vice versa. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -The format argument that is passed to System.String.Format does not contain a format item that corresponds to each object argument, or vice versa. +--- ## [CA2242](https://docs.microsoft.com/visualstudio/code-quality/ca2242): Test for NaN correctly +This expression tests a value against Single.Nan or Double.Nan. Use Single.IsNan(Single) or Double.IsNan(Double) to test the value. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -This expression tests a value against Single.Nan or Double.Nan. Use Single.IsNan(Single) or Double.IsNan(Double) to test the value. +--- ## [CA2243](https://docs.microsoft.com/visualstudio/code-quality/ca2243): Attribute string literals should parse correctly +The string literal parameter of an attribute does not parse correctly for a URL, a GUID, or a version. + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Warning| |CodeFix|False| - -### Rule description - -The string literal parameter of an attribute does not parse correctly for a URL, a GUID, or a version. +--- ## [CA2244](https://docs.microsoft.com/visualstudio/code-quality/ca2244): Do not duplicate indexed element initializations +Indexed elements in objects initializers must initialize unique elements. A duplicate index might overwrite a previous element initialization. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -Indexed elements in objects initializers must initialize unique elements. A duplicate index might overwrite a previous element initialization. +--- ## [CA2245](https://docs.microsoft.com/visualstudio/code-quality/ca2245): Do not assign a property to itself +The property {0} should not be assigned to itself + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -The property {0} should not be assigned to itself +--- ## [CA2246](https://docs.microsoft.com/visualstudio/code-quality/ca2246): Assigning symbol and its member in the same statement +Assigning to a symbol and its member (field/property) in the same statement is not recommended. It is not clear if the member access was intended to use symbol's old value prior to the assignment or new value from the assignment in this statement. For clarity, consider splitting the assignments into separate statements. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -Assigning to a symbol and its member (field/property) in the same statement is not recommended. It is not clear if the member access was intended to use symbol's old value prior to the assignment or new value from the assignment in this statement. For clarity, consider splitting the assignments into separate statements. +--- ## [CA2247](https://docs.microsoft.com/visualstudio/code-quality/ca2247): Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum +TaskCompletionSource has constructors that take TaskCreationOptions that control the underlying Task, and constructors that take object state that's stored in the task. Accidentally passing a TaskContinuationOptions instead of a TaskCreationOptions will result in the call treating the options as state. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -TaskCompletionSource has constructors that take TaskCreationOptions that control the underlying Task, and constructors that take object state that's stored in the task. Accidentally passing a TaskContinuationOptions instead of a TaskCreationOptions will result in the call treating the options as state. +--- ## [CA2248](https://docs.microsoft.com/visualstudio/code-quality/ca2248): Provide correct 'enum' argument to 'Enum.HasFlag' +'Enum.HasFlag' method expects the 'enum' argument to be of the same 'enum' type as the instance on which the method is invoked and that this 'enum' is marked with 'System.FlagsAttribute'. If these are different 'enum' types, an unhandled exception will be thrown at runtime. If the 'enum' type is not marked with 'System.FlagsAttribute' the call will always return 'false' at runtime. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|False| - -### Rule description - -'Enum.HasFlag' method expects the 'enum' argument to be of the same 'enum' type as the instance on which the method is invoked and that this 'enum' is marked with 'System.FlagsAttribute'. If these are different 'enum' types, an unhandled exception will be thrown at runtime. If the 'enum' type is not marked with 'System.FlagsAttribute' the call will always return 'false' at runtime. +--- ## [CA2249](https://docs.microsoft.com/visualstudio/code-quality/ca2249): Consider using 'string.Contains' instead of 'string.IndexOf' +Calls to 'string.IndexOf' where the result is used to check for the presence/absence of a substring can be replaced by 'string.Contains'. + |Item|Value| |-|-| |Category|Usage| |Enabled|True| |Severity|Info| |CodeFix|True| - -### Rule description - -Calls to 'string.IndexOf' where the result is used to check for the presence/absence of a substring can be replaced by 'string.Contains'. +--- ## [CA2300](https://docs.microsoft.com/visualstudio/code-quality/ca2300): Do not use insecure deserializer BinaryFormatter -|Item|Value| -|-|-| -|Category|Security| -|Enabled|False| -|Severity|Warning| -|CodeFix|False| - -### Rule description - The method '{0}' is insecure when deserializing untrusted data. If you need to instead detect BinaryFormatter deserialization without a SerializationBinder set, then disable rule CA2300, and enable rules CA2301 and CA2302. -## [CA2301](https://docs.microsoft.com/visualstudio/code-quality/ca2301): Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2301](https://docs.microsoft.com/visualstudio/code-quality/ca2301): Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2302](https://docs.microsoft.com/visualstudio/code-quality/ca2302): Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2302](https://docs.microsoft.com/visualstudio/code-quality/ca2302): Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2305](https://docs.microsoft.com/visualstudio/code-quality/ca2305): Do not use insecure deserializer LosFormatter - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2305](https://docs.microsoft.com/visualstudio/code-quality/ca2305): Do not use insecure deserializer LosFormatter The method '{0}' is insecure when deserializing untrusted data. -## [CA2310](https://docs.microsoft.com/visualstudio/code-quality/ca2310): Do not use insecure deserializer NetDataContractSerializer - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2310](https://docs.microsoft.com/visualstudio/code-quality/ca2310): Do not use insecure deserializer NetDataContractSerializer The method '{0}' is insecure when deserializing untrusted data. If you need to instead detect NetDataContractSerializer deserialization without a SerializationBinder set, then disable rule CA2310, and enable rules CA2311 and CA2312. -## [CA2311](https://docs.microsoft.com/visualstudio/code-quality/ca2311): Do not deserialize without first setting NetDataContractSerializer.Binder - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2311](https://docs.microsoft.com/visualstudio/code-quality/ca2311): Do not deserialize without first setting NetDataContractSerializer.Binder The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2312](https://docs.microsoft.com/visualstudio/code-quality/ca2312): Ensure NetDataContractSerializer.Binder is set before deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2312](https://docs.microsoft.com/visualstudio/code-quality/ca2312): Ensure NetDataContractSerializer.Binder is set before deserializing The method '{0}' is insecure when deserializing untrusted data without a SerializationBinder to restrict the type of objects in the deserialized object graph. -## [CA2315](https://docs.microsoft.com/visualstudio/code-quality/ca2315): Do not use insecure deserializer ObjectStateFormatter - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2315](https://docs.microsoft.com/visualstudio/code-quality/ca2315): Do not use insecure deserializer ObjectStateFormatter The method '{0}' is insecure when deserializing untrusted data. -## [CA2321](https://docs.microsoft.com/visualstudio/code-quality/ca2321): Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2321](https://docs.microsoft.com/visualstudio/code-quality/ca2321): Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver The method '{0}' is insecure when deserializing untrusted data with a JavaScriptSerializer initialized with a SimpleTypeResolver. Initialize JavaScriptSerializer without a JavaScriptTypeResolver specified, or initialize with a JavaScriptTypeResolver that limits the types of objects in the deserialized object graph. -## [CA2322](https://docs.microsoft.com/visualstudio/code-quality/ca2322): Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2322](https://docs.microsoft.com/visualstudio/code-quality/ca2322): Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing The method '{0}' is insecure when deserializing untrusted data with a JavaScriptSerializer initialized with a SimpleTypeResolver. Ensure that the JavaScriptSerializer is initialized without a JavaScriptTypeResolver specified, or initialized with a JavaScriptTypeResolver that limits the types of objects in the deserialized object graph. -## [CA2326](https://docs.microsoft.com/visualstudio/code-quality/ca2326): Do not use TypeNameHandling values other than None - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2326](https://docs.microsoft.com/visualstudio/code-quality/ca2326): Do not use TypeNameHandling values other than None Deserializing JSON when using a TypeNameHandling value other than None can be insecure. If you need to instead detect Json.NET deserialization when a SerializationBinder isn't specified, then disable rule CA2326, and enable rules CA2327, CA2328, CA2329, and CA2330. -## [CA2327](https://docs.microsoft.com/visualstudio/code-quality/ca2327): Do not use insecure JsonSerializerSettings - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2327](https://docs.microsoft.com/visualstudio/code-quality/ca2327): Do not use insecure JsonSerializerSettings When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using JsonSerializerSettings, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2328](https://docs.microsoft.com/visualstudio/code-quality/ca2328): Ensure that JsonSerializerSettings are secure - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2328](https://docs.microsoft.com/visualstudio/code-quality/ca2328): Ensure that JsonSerializerSettings are secure When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using JsonSerializerSettings, ensure TypeNameHandling.None is specified, or for values other than None, ensure a SerializationBinder is specified to restrict deserialized types. -## [CA2329](https://docs.microsoft.com/visualstudio/code-quality/ca2329): Do not deserialize with JsonSerializer using an insecure configuration - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2329](https://docs.microsoft.com/visualstudio/code-quality/ca2329): Do not deserialize with JsonSerializer using an insecure configuration When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using deserializing JsonSerializer, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2330](https://docs.microsoft.com/visualstudio/code-quality/ca2330): Ensure that JsonSerializer has a secure configuration when deserializing - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2330](https://docs.microsoft.com/visualstudio/code-quality/ca2330): Ensure that JsonSerializer has a secure configuration when deserializing When deserializing untrusted input, allowing arbitrary types to be deserialized is insecure. When using deserializing JsonSerializer, use TypeNameHandling.None, or for values other than None, restrict deserialized types with a SerializationBinder. -## [CA2350](https://docs.microsoft.com/visualstudio/code-quality/ca2350): Do not use DataTable.ReadXml() with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2350](https://docs.microsoft.com/visualstudio/code-quality/ca2350): Do not use DataTable.ReadXml() with untrusted data The method '{0}' is insecure when deserializing untrusted data -## [CA2351](https://docs.microsoft.com/visualstudio/code-quality/ca2351): Do not use DataSet.ReadXml() with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2351](https://docs.microsoft.com/visualstudio/code-quality/ca2351): Do not use DataSet.ReadXml() with untrusted data The method '{0}' is insecure when deserializing untrusted data -## [CA2352](https://docs.microsoft.com/visualstudio/code-quality/ca2352): Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2352](https://docs.microsoft.com/visualstudio/code-quality/ca2352): Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks When deserializing untrusted input with an IFormatter-based serializer, deserializing a {0} object is insecure. '{1}' either is or derives from {0}. -## [CA2353](https://docs.microsoft.com/visualstudio/code-quality/ca2353): Unsafe DataSet or DataTable in serializable type - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2353](https://docs.microsoft.com/visualstudio/code-quality/ca2353): Unsafe DataSet or DataTable in serializable type When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2354](https://docs.microsoft.com/visualstudio/code-quality/ca2354): Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2354](https://docs.microsoft.com/visualstudio/code-quality/ca2354): Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2355](https://docs.microsoft.com/visualstudio/code-quality/ca2355): Unsafe DataSet or DataTable type found in deserializable object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2355](https://docs.microsoft.com/visualstudio/code-quality/ca2355): Unsafe DataSet or DataTable type found in deserializable object graph When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2356](https://docs.microsoft.com/visualstudio/code-quality/ca2356): Unsafe DataSet or DataTable type in web deserializable object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2356](https://docs.microsoft.com/visualstudio/code-quality/ca2356): Unsafe DataSet or DataTable type in web deserializable object graph When deserializing untrusted input, deserializing a {0} object is insecure. '{1}' either is or derives from {0} -## [CA2361](https://docs.microsoft.com/visualstudio/code-quality/ca2361): Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2361](https://docs.microsoft.com/visualstudio/code-quality/ca2361): Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data The method '{0}' is insecure when deserializing untrusted data. Make sure that autogenerated class containing the '{0}' call is not deserialized with untrusted data. -## [CA2362](https://docs.microsoft.com/visualstudio/code-quality/ca2362): Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA2362](https://docs.microsoft.com/visualstudio/code-quality/ca2362): Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks When deserializing untrusted input with an IFormatter-based serializer, deserializing a {0} object is insecure. '{1}' either is or derives from {0}. Ensure that the autogenerated type is never deserialized with untrusted data. -## [CA3001](https://docs.microsoft.com/visualstudio/code-quality/ca3001): Review code for SQL injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3001](https://docs.microsoft.com/visualstudio/code-quality/ca3001): Review code for SQL injection vulnerabilities Potential SQL injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3002](https://docs.microsoft.com/visualstudio/code-quality/ca3002): Review code for XSS vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3002](https://docs.microsoft.com/visualstudio/code-quality/ca3002): Review code for XSS vulnerabilities Potential cross-site scripting (XSS) vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3003](https://docs.microsoft.com/visualstudio/code-quality/ca3003): Review code for file path injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3003](https://docs.microsoft.com/visualstudio/code-quality/ca3003): Review code for file path injection vulnerabilities Potential file path injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3004](https://docs.microsoft.com/visualstudio/code-quality/ca3004): Review code for information disclosure vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3004](https://docs.microsoft.com/visualstudio/code-quality/ca3004): Review code for information disclosure vulnerabilities Potential information disclosure vulnerability was found where '{0}' in method '{1}' may contain unintended information from '{2}' in method '{3}'. -## [CA3005](https://docs.microsoft.com/visualstudio/code-quality/ca3005): Review code for LDAP injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3005](https://docs.microsoft.com/visualstudio/code-quality/ca3005): Review code for LDAP injection vulnerabilities Potential LDAP injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3006](https://docs.microsoft.com/visualstudio/code-quality/ca3006): Review code for process command injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3006](https://docs.microsoft.com/visualstudio/code-quality/ca3006): Review code for process command injection vulnerabilities Potential process command injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3007](https://docs.microsoft.com/visualstudio/code-quality/ca3007): Review code for open redirect vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3007](https://docs.microsoft.com/visualstudio/code-quality/ca3007): Review code for open redirect vulnerabilities Potential open redirect vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3008](https://docs.microsoft.com/visualstudio/code-quality/ca3008): Review code for XPath injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3008](https://docs.microsoft.com/visualstudio/code-quality/ca3008): Review code for XPath injection vulnerabilities Potential XPath injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3009](https://docs.microsoft.com/visualstudio/code-quality/ca3009): Review code for XML injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3009](https://docs.microsoft.com/visualstudio/code-quality/ca3009): Review code for XML injection vulnerabilities Potential XML injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3010](https://docs.microsoft.com/visualstudio/code-quality/ca3010): Review code for XAML injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3010](https://docs.microsoft.com/visualstudio/code-quality/ca3010): Review code for XAML injection vulnerabilities Potential XAML injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3011](https://docs.microsoft.com/visualstudio/code-quality/ca3011): Review code for DLL injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3011](https://docs.microsoft.com/visualstudio/code-quality/ca3011): Review code for DLL injection vulnerabilities Potential DLL injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3012](https://docs.microsoft.com/visualstudio/code-quality/ca3012): Review code for regex injection vulnerabilities - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3012](https://docs.microsoft.com/visualstudio/code-quality/ca3012): Review code for regex injection vulnerabilities Potential regex injection vulnerability was found where '{0}' in method '{1}' may be tainted by user-controlled data from '{2}' in method '{3}'. -## [CA3061](https://docs.microsoft.com/visualstudio/code-quality/ca3061): Do Not Add Schema By URL - |Item|Value| |-|-| |Category|Security| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA3061](https://docs.microsoft.com/visualstudio/code-quality/ca3061): Do Not Add Schema By URL This overload of XmlSchemaCollection.Add method internally enables DTD processing on the XML reader instance used, and uses UrlResolver for resolving external XML entities. The outcome is information disclosure. Content from file system or network shares for the machine processing the XML can be exposed to attacker. In addition, an attacker can use this as a DoS vector. -## [CA3075](https://docs.microsoft.com/visualstudio/code-quality/ca3075): Insecure DTD processing in XML - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description - -Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when invoking XmlReader.Create(), setting the InnerXml property of the XmlDocument and enabling DTD processing using XmlUrlResolver insecurely can lead to information disclosure. Replace it with a call to the Load() method overload that takes an XmlReader instance, use XmlReader.Create() to accept XmlReaderSettings arguments or consider explicitly setting secure values. The DataViewSettingCollectionString property of DataViewManager should always be assigned from a trusted source, the DtdProcessing property should be set to false, and the XmlResolver property should be changed to XmlSecureResolver or null.  +## [CA3075](https://docs.microsoft.com/visualstudio/code-quality/ca3075): Insecure DTD processing in XML -## [CA3076](https://docs.microsoft.com/visualstudio/code-quality/ca3076): Insecure XSLT script processing. +Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when invoking XmlReader.Create(), setting the InnerXml property of the XmlDocument and enabling DTD processing using XmlUrlResolver insecurely can lead to information disclosure. Replace it with a call to the Load() method overload that takes an XmlReader instance, use XmlReader.Create() to accept XmlReaderSettings arguments or consider explicitly setting secure values. The DataViewSettingCollectionString property of DataViewManager should always be assigned from a trusted source, the DtdProcessing property should be set to false, and the XmlResolver property should be changed to XmlSecureResolver or null. |Item|Value| |-|-| @@ -2517,25 +2314,23 @@ Using XmlTextReader.Load(), creating an insecure XmlReaderSettings instance when |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA3076](https://docs.microsoft.com/visualstudio/code-quality/ca3076): Insecure XSLT script processing. Providing an insecure XsltSettings instance and an insecure XmlResolver instance to XslCompiledTransform.Load method is potentially unsafe as it allows processing script within XSL, which on an untrusted XSL input may lead to malicious code execution. Either replace the insecure XsltSettings argument with XsltSettings.Default or an instance that has disabled document function and script execution, or replace the XmlResolver argurment with null or an XmlSecureResolver instance. This message may be suppressed if the input is known to be from a trusted source and external resource resolution from locations that are not known in advance must be supported. -## [CA3077](https://docs.microsoft.com/visualstudio/code-quality/ca3077): Insecure Processing in API Design, XmlDocument and XmlTextReader - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description - -Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocument and using XmlUrlResolver for resolving external XML entities may lead to information disclosure. Ensure to set the XmlResolver property to null, create an instance of XmlSecureResolver when processing untrusted input, or use XmlReader.Create method with a secure XmlReaderSettings argument. Unless you need to enable it, ensure the DtdProcessing property is set to false.  +## [CA3077](https://docs.microsoft.com/visualstudio/code-quality/ca3077): Insecure Processing in API Design, XmlDocument and XmlTextReader -## [CA3147](https://docs.microsoft.com/visualstudio/code-quality/ca3147): Mark Verb Handlers With Validate Antiforgery Token +Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocument and using XmlUrlResolver for resolving external XML entities may lead to information disclosure. Ensure to set the XmlResolver property to null, create an instance of XmlSecureResolver when processing untrusted input, or use XmlReader.Create method with a secure XmlReaderSettings argument. Unless you need to enable it, ensure the DtdProcessing property is set to false. |Item|Value| |-|-| @@ -2543,658 +2338,616 @@ Enabling DTD processing on all instances derived from XmlTextReader or  XmlDocu |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA3147](https://docs.microsoft.com/visualstudio/code-quality/ca3147): Mark Verb Handlers With Validate Antiforgery Token Missing ValidateAntiForgeryTokenAttribute on controller action {0} -## [CA5350](https://docs.microsoft.com/visualstudio/code-quality/ca5350): Do Not Use Weak Cryptographic Algorithms - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5350](https://docs.microsoft.com/visualstudio/code-quality/ca5350): Do Not Use Weak Cryptographic Algorithms Cryptographic algorithms degrade over time as attacks become for advances to attacker get access to more computation. Depending on the type and application of this cryptographic algorithm, further degradation of the cryptographic strength of it may allow attackers to read enciphered messages, tamper with enciphered  messages, forge digital signatures, tamper with hashed content, or otherwise compromise any cryptosystem based on this algorithm. Replace encryption uses with the AES algorithm (AES-256, AES-192 and AES-128 are acceptable) with a key length greater than or equal to 128 bits. Replace hashing uses with a hashing function in the SHA-2 family, such as SHA-2 512, SHA-2 384, or SHA-2 256. -## [CA5351](https://docs.microsoft.com/visualstudio/code-quality/ca5351): Do Not Use Broken Cryptographic Algorithms - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5351](https://docs.microsoft.com/visualstudio/code-quality/ca5351): Do Not Use Broken Cryptographic Algorithms An attack making it computationally feasible to break this algorithm exists. This allows attackers to break the cryptographic guarantees it is designed to provide. Depending on the type and application of this cryptographic algorithm, this may allow attackers to read enciphered messages, tamper with enciphered  messages, forge digital signatures, tamper with hashed content, or otherwise compromise any cryptosystem based on this algorithm. Replace encryption uses with the AES algorithm (AES-256, AES-192 and AES-128 are acceptable) with a key length greater than or equal to 128 bits. Replace hashing uses with a hashing function in the SHA-2 family, such as SHA512, SHA384, or SHA256. Replace digital signature uses with RSA with a key length greater than or equal to 2048-bits, or ECDSA with a key length greater than or equal to 256 bits. -## [CA5358](https://docs.microsoft.com/visualstudio/code-quality/ca5358): Review cipher mode usage with cryptography experts - |Item|Value| |-|-| |Category|Security| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5358](https://docs.microsoft.com/visualstudio/code-quality/ca5358): Review cipher mode usage with cryptography experts These cipher modes might be vulnerable to attacks. Consider using recommended modes (CBC, CTS). -## [CA5359](https://docs.microsoft.com/visualstudio/code-quality/ca5359): Do Not Disable Certificate Validation - |Item|Value| |-|-| |Category|Security| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5359](https://docs.microsoft.com/visualstudio/code-quality/ca5359): Do Not Disable Certificate Validation A certificate can help authenticate the identity of the server. Clients should validate the server certificate to ensure requests are sent to the intended server. If the ServerCertificateValidationCallback always returns 'true', any certificate will pass validation. -## [CA5360](https://docs.microsoft.com/visualstudio/code-quality/ca5360): Do Not Call Dangerous Methods In Deserialization - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5360](https://docs.microsoft.com/visualstudio/code-quality/ca5360): Do Not Call Dangerous Methods In Deserialization Insecure Deserialization is a vulnerability which occurs when untrusted data is used to abuse the logic of an application, inflict a Denial-of-Service (DoS) attack, or even execute arbitrary code upon it being deserialized. It’s frequently possible for malicious users to abuse these deserialization features when the application is deserializing untrusted data which is under their control. Specifically, invoke dangerous methods in the process of deserialization. Successful insecure deserialization attacks could allow an attacker to carry out attacks such as DoS attacks, authentication bypasses, and remote code execution. -## [CA5361](https://docs.microsoft.com/visualstudio/code-quality/ca5361): Do Not Disable SChannel Use of Strong Crypto - |Item|Value| |-|-| |Category|Security| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5361](https://docs.microsoft.com/visualstudio/code-quality/ca5361): Do Not Disable SChannel Use of Strong Crypto Starting with the .NET Framework 4.6, the System.Net.ServicePointManager and System.Net.Security.SslStream classes are recommeded to use new protocols. The old ones have protocol weaknesses and are not supported. Setting Switch.System.Net.DontEnableSchUseStrongCrypto with true will use the old weak crypto check and opt out of the protocol migration. -## [CA5362](https://docs.microsoft.com/visualstudio/code-quality/ca5362): Potential reference cycle in deserialized object graph - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5362](https://docs.microsoft.com/visualstudio/code-quality/ca5362): Potential reference cycle in deserialized object graph Review code that processes untrusted deserialized data for handling of unexpected reference cycles. An unexpected reference cycle should not cause the code to enter an infinite loop. Otherwise, an unexpected reference cycle can allow an attacker to DOS or exhaust the memory of the process when deserializing untrusted data. -## [CA5363](https://docs.microsoft.com/visualstudio/code-quality/ca5363): Do Not Disable Request Validation - |Item|Value| |-|-| |Category|Security| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5363](https://docs.microsoft.com/visualstudio/code-quality/ca5363): Do Not Disable Request Validation Request validation is a feature in ASP.NET that examines HTTP requests and determines whether they contain potentially dangerous content. This check adds protection from markup or code in the URL query string, cookies, or posted form values that might have been added for malicious purposes. So, it is generally desirable and should be left enabled for defense in depth. -## [CA5364](https://docs.microsoft.com/visualstudio/code-quality/ca5364): Do Not Use Deprecated Security Protocols - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5364](https://docs.microsoft.com/visualstudio/code-quality/ca5364): Do Not Use Deprecated Security Protocols Using a deprecated security protocol rather than the system default is risky. -## [CA5365](https://docs.microsoft.com/visualstudio/code-quality/ca5365): Do Not Disable HTTP Header Checking - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5365](https://docs.microsoft.com/visualstudio/code-quality/ca5365): Do Not Disable HTTP Header Checking HTTP header checking enables encoding of the carriage return and newline characters, \r and \n, that are found in response headers. This encoding can help to avoid injection attacks that exploit an application that echoes untrusted data contained by the header. -## [CA5366](https://docs.microsoft.com/visualstudio/code-quality/ca5366): Use XmlReader For DataSet Read Xml - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5366](https://docs.microsoft.com/visualstudio/code-quality/ca5366): Use XmlReader For DataSet Read Xml Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5367](https://docs.microsoft.com/visualstudio/code-quality/ca5367): Do Not Serialize Types With Pointer Fields - |Item|Value| |-|-| |Category|Security| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5367](https://docs.microsoft.com/visualstudio/code-quality/ca5367): Do Not Serialize Types With Pointer Fields Pointers are not "type safe" in the sense that you cannot guarantee the correctness of the memory they point at. So, serializing types with pointer fields is dangerous, as it may allow an attacker to control the pointer. -## [CA5368](https://docs.microsoft.com/visualstudio/code-quality/ca5368): Set ViewStateUserKey For Classes Derived From Page - |Item|Value| |-|-| |Category|Security| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5368](https://docs.microsoft.com/visualstudio/code-quality/ca5368): Set ViewStateUserKey For Classes Derived From Page Setting the ViewStateUserKey property can help you prevent attacks on your application by allowing you to assign an identifier to the view-state variable for individual users so that they cannot use the variable to generate an attack. Otherwise, there will be cross-site request forgery vulnerabilities. -## [CA5369](https://docs.microsoft.com/visualstudio/code-quality/ca5369): Use XmlReader For Deserialize - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5369](https://docs.microsoft.com/visualstudio/code-quality/ca5369): Use XmlReader For Deserialize Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5370](https://docs.microsoft.com/visualstudio/code-quality/ca5370): Use XmlReader For Validating Reader - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5370](https://docs.microsoft.com/visualstudio/code-quality/ca5370): Use XmlReader For Validating Reader Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5371](https://docs.microsoft.com/visualstudio/code-quality/ca5371): Use XmlReader For Schema Read - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5371](https://docs.microsoft.com/visualstudio/code-quality/ca5371): Use XmlReader For Schema Read Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5372](https://docs.microsoft.com/visualstudio/code-quality/ca5372): Use XmlReader For XPathDocument - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5372](https://docs.microsoft.com/visualstudio/code-quality/ca5372): Use XmlReader For XPathDocument Processing XML from untrusted data may load dangerous external references, which should be restricted by using an XmlReader with a secure resolver or with DTD processing disabled. -## [CA5373](https://docs.microsoft.com/visualstudio/code-quality/ca5373): Do not use obsolete key derivation function - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5373](https://docs.microsoft.com/visualstudio/code-quality/ca5373): Do not use obsolete key derivation function Password-based key derivation should use PBKDF2 with SHA-2. Avoid using PasswordDeriveBytes since it generates a PBKDF1 key. Avoid using Rfc2898DeriveBytes.CryptDeriveKey since it doesn't use the iteration count or salt. -## [CA5374](https://docs.microsoft.com/visualstudio/code-quality/ca5374): Do Not Use XslTransform - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5374](https://docs.microsoft.com/visualstudio/code-quality/ca5374): Do Not Use XslTransform Do not use XslTransform. It does not restrict potentially dangerous external references. -## [CA5375](https://docs.microsoft.com/visualstudio/code-quality/ca5375): Do Not Use Account Shared Access Signature - |Item|Value| |-|-| |Category|Security| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5375](https://docs.microsoft.com/visualstudio/code-quality/ca5375): Do Not Use Account Shared Access Signature Shared Access Signatures(SAS) are a vital part of the security model for any application using Azure Storage, they should provide limited and safe permissions to your storage account to clients that don't have the account key. All of the operations available via a service SAS are also available via an account SAS, that is, account SAS is too powerful. So it is recommended to use Service SAS to delegate access more carefully. -## [CA5376](https://docs.microsoft.com/visualstudio/code-quality/ca5376): Use SharedAccessProtocol HttpsOnly - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5376](https://docs.microsoft.com/visualstudio/code-quality/ca5376): Use SharedAccessProtocol HttpsOnly HTTPS encrypts network traffic. Use HttpsOnly, rather than HttpOrHttps, to ensure network traffic is always encrypted to help prevent disclosure of sensitive data. -## [CA5377](https://docs.microsoft.com/visualstudio/code-quality/ca5377): Use Container Level Access Policy - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5377](https://docs.microsoft.com/visualstudio/code-quality/ca5377): Use Container Level Access Policy No access policy identifier is specified, making tokens non-revocable. -## [CA5378](https://docs.microsoft.com/visualstudio/code-quality/ca5378): Do not disable ServicePointManagerSecurityProtocols - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5378](https://docs.microsoft.com/visualstudio/code-quality/ca5378): Do not disable ServicePointManagerSecurityProtocols Do not set Switch.System.ServiceModel.DisableUsingServicePointManagerSecurityProtocols to true. Setting this switch limits Windows Communication Framework (WCF) to using Transport Layer Security (TLS) 1.0, which is insecure and obsolete. -## [CA5379](https://docs.microsoft.com/visualstudio/code-quality/ca5379): Do Not Use Weak Key Derivation Function Algorithm - |Item|Value| |-|-| |Category|Security| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5379](https://docs.microsoft.com/visualstudio/code-quality/ca5379): Do Not Use Weak Key Derivation Function Algorithm Some implementations of the Rfc2898DeriveBytes class allow for a hash algorithm to be specified in a constructor parameter or overwritten in the HashAlgorithm property. If a hash algorithm is specified, then it should be SHA-256 or higher. -## [CA5380](https://docs.microsoft.com/visualstudio/code-quality/ca5380): Do Not Add Certificates To Root Store - |Item|Value| |-|-| |Category|Security| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5380](https://docs.microsoft.com/visualstudio/code-quality/ca5380): Do Not Add Certificates To Root Store By default, the Trusted Root Certification Authorities certificate store is configured with a set of public CAs that has met the requirements of the Microsoft Root Certificate Program. Since all trusted root CAs can issue certificates for any domain, an attacker can pick a weak or coercible CA that you install by yourself to target for an attack – and a single vulnerable, malicious or coercible CA undermines the security of the entire system. To make matters worse, these attacks can go unnoticed quite easily. -## [CA5381](https://docs.microsoft.com/visualstudio/code-quality/ca5381): Ensure Certificates Are Not Added To Root Store - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5381](https://docs.microsoft.com/visualstudio/code-quality/ca5381): Ensure Certificates Are Not Added To Root Store By default, the Trusted Root Certification Authorities certificate store is configured with a set of public CAs that has met the requirements of the Microsoft Root Certificate Program. Since all trusted root CAs can issue certificates for any domain, an attacker can pick a weak or coercible CA that you install by yourself to target for an attack – and a single vulnerable, malicious or coercible CA undermines the security of the entire system. To make matters worse, these attacks can go unnoticed quite easily. -## [CA5382](https://docs.microsoft.com/visualstudio/code-quality/ca5382): Use Secure Cookies In ASP.Net Core - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5382](https://docs.microsoft.com/visualstudio/code-quality/ca5382): Use Secure Cookies In ASP.Net Core Applications available over HTTPS must use secure cookies. -## [CA5383](https://docs.microsoft.com/visualstudio/code-quality/ca5383): Ensure Use Secure Cookies In ASP.Net Core - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5383](https://docs.microsoft.com/visualstudio/code-quality/ca5383): Ensure Use Secure Cookies In ASP.Net Core Applications available over HTTPS must use secure cookies. -## [CA5384](https://docs.microsoft.com/visualstudio/code-quality/ca5384): Do Not Use Digital Signature Algorithm (DSA) - |Item|Value| |-|-| |Category|Security| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5384](https://docs.microsoft.com/visualstudio/code-quality/ca5384): Do Not Use Digital Signature Algorithm (DSA) DSA is too weak to use. -## [CA5385](https://docs.microsoft.com/visualstudio/code-quality/ca5385): Use Rivest–Shamir–Adleman (RSA) Algorithm With Sufficient Key Size - |Item|Value| |-|-| |Category|Security| |Enabled|True| |Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5385](https://docs.microsoft.com/visualstudio/code-quality/ca5385): Use Rivest–Shamir–Adleman (RSA) Algorithm With Sufficient Key Size Encryption algorithms are vulnerable to brute force attacks when too small a key size is used. -## [CA5386](https://docs.microsoft.com/visualstudio/code-quality/ca5386): Avoid hardcoding SecurityProtocolType value - |Item|Value| |-|-| |Category|Security| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5386](https://docs.microsoft.com/visualstudio/code-quality/ca5386): Avoid hardcoding SecurityProtocolType value Avoid hardcoding SecurityProtocolType {0}, and instead use SecurityProtocolType.SystemDefault to allow the operating system to choose the best Transport Layer Security protocol to use. -## [CA5387](https://docs.microsoft.com/visualstudio/code-quality/ca5387): Do Not Use Weak Key Derivation Function With Insufficient Iteration Count - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5387](https://docs.microsoft.com/visualstudio/code-quality/ca5387): Do Not Use Weak Key Derivation Function With Insufficient Iteration Count When deriving cryptographic keys from user-provided inputs such as password, use sufficient iteration count (at least 100k). -## [CA5388](https://docs.microsoft.com/visualstudio/code-quality/ca5388): Ensure Sufficient Iteration Count When Using Weak Key Derivation Function - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5388](https://docs.microsoft.com/visualstudio/code-quality/ca5388): Ensure Sufficient Iteration Count When Using Weak Key Derivation Function When deriving cryptographic keys from user-provided inputs such as password, use sufficient iteration count (at least 100k). -## [CA5389](https://docs.microsoft.com/visualstudio/code-quality/ca5389): Do Not Add Archive Item's Path To The Target File System Path - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5389](https://docs.microsoft.com/visualstudio/code-quality/ca5389): Do Not Add Archive Item's Path To The Target File System Path When extracting files from an archive and using the archive item's path, check if the path is safe. Archive path can be relative and can lead to file system access outside of the expected file system target path, leading to malicious config changes and remote code execution via lay-and-wait technique. -## [CA5390](https://docs.microsoft.com/visualstudio/code-quality/ca5390): Do not hard-code encryption key - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5390](https://docs.microsoft.com/visualstudio/code-quality/ca5390): Do not hard-code encryption key SymmetricAlgorithm's .Key property, or a method's rgbKey parameter, should never be a hard-coded value. -## [CA5391](https://docs.microsoft.com/visualstudio/code-quality/ca5391): Use antiforgery tokens in ASP.NET Core MVC controllers - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5391](https://docs.microsoft.com/visualstudio/code-quality/ca5391): Use antiforgery tokens in ASP.NET Core MVC controllers Handling a POST, PUT, PATCH, or DELETE request without validating an antiforgery token may be vulnerable to cross-site request forgery attacks. A cross-site request forgery attack can send malicious requests from an authenticated user to your ASP.NET Core MVC controller. -## [CA5392](https://docs.microsoft.com/visualstudio/code-quality/ca5392): Use DefaultDllImportSearchPaths attribute for P/Invokes - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5392](https://docs.microsoft.com/visualstudio/code-quality/ca5392): Use DefaultDllImportSearchPaths attribute for P/Invokes By default, P/Invokes using DllImportAttribute probe a number of directories, including the current working directory for the library to load. This can be a security issue for certain applications, leading to DLL hijacking. -## [CA5393](https://docs.microsoft.com/visualstudio/code-quality/ca5393): Do not use unsafe DllImportSearchPath value - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5393](https://docs.microsoft.com/visualstudio/code-quality/ca5393): Do not use unsafe DllImportSearchPath value There could be a malicious DLL in the default DLL search directories. Or, depending on where your application is run from, there could be a malicious DLL in the application's directory. Use a DllImportSearchPath value that specifies an explicit search path instead. The DllImportSearchPath flags that this rule looks for can be configured in .editorconfig. -## [CA5394](https://docs.microsoft.com/visualstudio/code-quality/ca5394): Do not use insecure randomness - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5394](https://docs.microsoft.com/visualstudio/code-quality/ca5394): Do not use insecure randomness Using a cryptographically weak pseudo-random number generator may allow an attacker to predict what security-sensitive value will be generated. Use a cryptographically strong random number generator if an unpredictable value is required, or ensure that weak pseudo-random numbers aren't used in a security-sensitive manner. -## [CA5395](https://docs.microsoft.com/visualstudio/code-quality/ca5395): Miss HttpVerb attribute for action methods - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5395](https://docs.microsoft.com/visualstudio/code-quality/ca5395): Miss HttpVerb attribute for action methods All the methods that create, edit, delete, or otherwise modify data do so in the [HttpPost] overload of the method, which needs to be protected with the anti forgery attribute from request forgery. Performing a GET operation should be a safe operation that has no side effects and doesn't modify your persisted data. -## [CA5396](https://docs.microsoft.com/visualstudio/code-quality/ca5396): Set HttpOnly to true for HttpCookie - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5396](https://docs.microsoft.com/visualstudio/code-quality/ca5396): Set HttpOnly to true for HttpCookie As a defense in depth measure, ensure security sensitive HTTP cookies are marked as HttpOnly. This indicates web browsers should disallow scripts from accessing the cookies. Injected malicious scripts are a common way of stealing cookies. -## [CA5397](https://docs.microsoft.com/visualstudio/code-quality/ca5397): Do not use deprecated SslProtocols values - |Item|Value| |-|-| |Category|Security| -|Enabled|True| -|Severity|Hidden| +|Enabled|False| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5397](https://docs.microsoft.com/visualstudio/code-quality/ca5397): Do not use deprecated SslProtocols values Older protocol versions of Transport Layer Security (TLS) are less secure than TLS 1.2 and TLS 1.3, and are more likely to have new vulnerabilities. Avoid older protocol versions to minimize risk. -## [CA5398](https://docs.microsoft.com/visualstudio/code-quality/ca5398): Avoid hardcoded SslProtocols values - |Item|Value| |-|-| |Category|Security| -|Enabled|False| -|Severity|Warning| +|Enabled|True| +|Severity|Hidden| |CodeFix|False| +--- -### Rule description +## [CA5398](https://docs.microsoft.com/visualstudio/code-quality/ca5398): Avoid hardcoded SslProtocols values Current Transport Layer Security protocol versions may become deprecated if vulnerabilities are found. Avoid hardcoding SslProtocols values to keep your application secure. Use 'None' to let the Operating System choose a version. -## [CA5399](https://docs.microsoft.com/visualstudio/code-quality/ca5399): HttpClients should enable certificate revocation list checks - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5399](https://docs.microsoft.com/visualstudio/code-quality/ca5399): HttpClients should enable certificate revocation list checks Using HttpClient without providing a platform specific handler (WinHttpHandler or CurlHandler or HttpClientHandler) where the CheckCertificateRevocationList property is set to true, will allow revoked certificates to be accepted by the HttpClient as valid. -## [CA5400](https://docs.microsoft.com/visualstudio/code-quality/ca5400): Ensure HttpClient certificate revocation list check is not disabled - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5400](https://docs.microsoft.com/visualstudio/code-quality/ca5400): Ensure HttpClient certificate revocation list check is not disabled Using HttpClient without providing a platform specific handler (WinHttpHandler or CurlHandler or HttpClientHandler) where the CheckCertificateRevocationList property is set to true, will allow revoked certificates to be accepted by the HttpClient as valid. -## [CA5401](https://docs.microsoft.com/visualstudio/code-quality/ca5401): Do not use CreateEncryptor with non-default IV - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5401](https://docs.microsoft.com/visualstudio/code-quality/ca5401): Do not use CreateEncryptor with non-default IV Symmetric encryption should always use a non-repeatable initialization vector to prevent dictionary attacks. -## [CA5402](https://docs.microsoft.com/visualstudio/code-quality/ca5402): Use CreateEncryptor with the default IV - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5402](https://docs.microsoft.com/visualstudio/code-quality/ca5402): Use CreateEncryptor with the default IV Symmetric encryption should always use a non-repeatable initialization vector to prevent dictionary attacks. -## [CA5403](https://docs.microsoft.com/visualstudio/code-quality/ca5403): Do not hard-code certificate - |Item|Value| |-|-| |Category|Security| |Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [CA5403](https://docs.microsoft.com/visualstudio/code-quality/ca5403): Do not hard-code certificate Hard-coded certificates in source code are vulnerable to being exploited. -## [IL3000](https://docs.microsoft.com/visualstudio/code-quality/il3000): Avoid using accessing Assembly file path when publishing as a single-file - |Item|Value| |-|-| -|Category|Publish| -|Enabled|True| +|Category|Security| +|Enabled|False| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [IL3000](https://docs.microsoft.com/visualstudio/code-quality/il3000): Avoid using accessing Assembly file path when publishing as a single-file '{0}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. -## [IL3001](https://docs.microsoft.com/visualstudio/code-quality/il3001): Avoid using accessing Assembly file path when publishing as a single-file - |Item|Value| |-|-| |Category|Publish| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [IL3001](https://docs.microsoft.com/visualstudio/code-quality/il3001): Avoid using accessing Assembly file path when publishing as a single-file '{0}' will throw for assemblies embedded in a single-file app +|Item|Value| +|-|-| +|Category|Publish| +|Enabled|True| +|Severity|Warning| +|CodeFix|False| +--- diff --git a/src/NetAnalyzers/RulesMissingDocumentation.md b/src/NetAnalyzers/RulesMissingDocumentation.md index 4126869a38..dedfab7d66 100644 --- a/src/NetAnalyzers/RulesMissingDocumentation.md +++ b/src/NetAnalyzers/RulesMissingDocumentation.md @@ -1,6 +1,5 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| CA1416 | https://docs.microsoft.com/visualstudio/code-quality/ca1416 | Validate platform compatibility | -CA1834 | https://docs.microsoft.com/visualstudio/code-quality/ca1834 | Consider using 'StringBuilder.Append(char)' when applicable | diff --git a/src/PerformanceSensitiveAnalyzers/Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.md b/src/PerformanceSensitiveAnalyzers/Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.md index bc116b70b3..39a8026024 100644 --- a/src/PerformanceSensitiveAnalyzers/Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.md +++ b/src/PerformanceSensitiveAnalyzers/Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.md @@ -2,209 +2,192 @@ ## HAA0101: Array allocation for params parameter -|Item|Value| -|-|-| -|Category|Performance| -|Enabled|True| -|Severity|Warning| -|CodeFix|False| - -### Rule description - This call site is calling into a function with a 'params' parameter. This results in an array allocation. -## HAA0102: Non-overridden virtual method call on value type - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0102: Non-overridden virtual method call on value type Non-overridden virtual method call on a value type adds a boxing or constrained instruction -## [HAA0201](http://msdn.microsoft.com/en-us/library/2839d5h5(v=vs.110).aspx): Implicit string concatenation allocation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [HAA0201](http://msdn.microsoft.com/en-us/library/2839d5h5(v=vs.110).aspx): Implicit string concatenation allocation Considering using StringBuilder -## [HAA0202](http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx): Value type to reference type conversion allocation for string concatenation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [HAA0202](http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx): Value type to reference type conversion allocation for string concatenation Value type ({0}) is being boxed to a reference type for a string concatenation -## HAA0301: Closure Allocation Source - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0301: Closure Allocation Source Heap allocation of closure Captures: {0} -## HAA0302: Display class allocation to capture closure - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0302: Display class allocation to capture closure The compiler will emit a class that will hold this as a field to allow capturing of this closure -## HAA0303: Lambda or anonymous method in a generic method allocates a delegate instance - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0303: Lambda or anonymous method in a generic method allocates a delegate instance Considering moving this out of the generic method -## HAA0401: Possible allocation of reference type enumerator - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0401: Possible allocation of reference type enumerator Non-ValueType enumerator may result in a heap allocation -## HAA0501: Explicit new array type allocation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| -|Severity|Info| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0501: Explicit new array type allocation Explicit new array type allocation -## HAA0502: Explicit new reference type allocation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|False| +--- -### Rule description +## HAA0502: Explicit new reference type allocation Explicit new reference type allocation -## [HAA0503](http://msdn.microsoft.com/en-us/library/bb397696.aspx): Explicit new anonymous object allocation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|False| +--- -### Rule description +## [HAA0503](http://msdn.microsoft.com/en-us/library/bb397696.aspx): Explicit new anonymous object allocation Explicit new anonymous object allocation -## HAA0506: Let clause induced allocation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Info| |CodeFix|False| +--- -### Rule description +## HAA0506: Let clause induced allocation Let clause induced allocation -## HAA0601: Value type to reference type conversion causing boxing allocation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| -|Severity|Warning| +|Severity|Info| |CodeFix|False| +--- -### Rule description +## HAA0601: Value type to reference type conversion causing boxing allocation Value type to reference type conversion causes boxing at call site (here), and unboxing at the callee-site. Consider using generics if applicable. -## HAA0602: Delegate on struct instance caused a boxing allocation - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0602: Delegate on struct instance caused a boxing allocation Struct instance method being used for delegate creation, this will result in a boxing instruction -## HAA0603: Delegate allocation from a method group - |Item|Value| |-|-| |Category|Performance| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0603: Delegate allocation from a method group This will allocate a delegate instance -## HAA0604: Delegate allocation from a method group - |Item|Value| |-|-| |Category|Performance| |Enabled|True| -|Severity|Info| +|Severity|Warning| |CodeFix|False| +--- -### Rule description +## HAA0604: Delegate allocation from a method group This will allocate a delegate instance +|Item|Value| +|-|-| +|Category|Performance| +|Enabled|True| +|Severity|Info| +|CodeFix|False| +--- diff --git a/src/PerformanceSensitiveAnalyzers/RulesMissingDocumentation.md b/src/PerformanceSensitiveAnalyzers/RulesMissingDocumentation.md index 357e4a6871..785331fe40 100644 --- a/src/PerformanceSensitiveAnalyzers/RulesMissingDocumentation.md +++ b/src/PerformanceSensitiveAnalyzers/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md b/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md index 18445a3f5a..2496203f02 100644 --- a/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md +++ b/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md @@ -2,144 +2,132 @@ ## [RS0016](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Add public types and members to the declared API -|Item|Value| -|-|-| -|Category|ApiDesign| -|Enabled|True| -|Severity|Warning| -|CodeFix|True| - -### Rule description - All public types and members should be declared in PublicAPI.txt. This draws attention to API changes in the code reviews and source control history, and helps prevent breaking changes. -## [RS0017](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Remove deleted types and members from the declared API - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [RS0017](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Remove deleted types and members from the declared API When removing a public type or member the corresponding entry in PublicAPI.txt should also be removed. This draws attention to API changes in the code reviews and source control history, and helps prevent breaking changes. -## [RS0022](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Constructor make noninheritable base class inheritable - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS0022](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Constructor make noninheritable base class inheritable Constructor makes its noninheritable base class inheritable, thereby exposing its protected members. -## [RS0024](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): The contents of the public API files are invalid - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS0024](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): The contents of the public API files are invalid The contents of the public API files are invalid: {0} -## [RS0025](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Do not duplicate symbols in public API files - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS0025](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Do not duplicate symbols in public API files The symbol '{0}' appears more than once in the public API files. -## [RS0026](https://github.com/dotnet/roslyn/blob/master/docs/Adding%20Optional%20Parameters%20in%20Public%20API.md): Do not add multiple public overloads with optional parameters - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS0026](https://github.com/dotnet/roslyn/blob/master/docs/Adding%20Optional%20Parameters%20in%20Public%20API.md): Do not add multiple public overloads with optional parameters Symbol '{0}' violates the backcompat requirement: 'Do not add multiple overloads with optional parameters'. See '{1}' for details. -## [RS0027](https://github.com/dotnet/roslyn/blob/master/docs/Adding%20Optional%20Parameters%20in%20Public%20API.md): Public API with optional parameter(s) should have the most parameters amongst its public overloads. - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS0027](https://github.com/dotnet/roslyn/blob/master/docs/Adding%20Optional%20Parameters%20in%20Public%20API.md): Public API with optional parameter(s) should have the most parameters amongst its public overloads. Symbol '{0}' violates the backcompat requirement: 'Public API with optional parameter(s) should have the most parameters amongst its public overloads'. See '{1}' for details. -## [RS0036](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Annotate nullability of public types and members in the declared API - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| -|CodeFix|True| +|CodeFix|False| +--- -### Rule description +## [RS0036](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Annotate nullability of public types and members in the declared API All public types and members should be declared with nullability annotations in PublicAPI.txt. This draws attention to API nullability changes in the code reviews and source control history, and helps prevent breaking changes. -## [RS0037](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Enable tracking of nullability of reference types in the declared API - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|True| +--- -### Rule description +## [RS0037](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Enable tracking of nullability of reference types in the declared API PublicAPI.txt files should have `#nullable enable` to track nullability information, or this diagnostic should be suppressed. With nullability enabled, PublicAPI.txt records which types are nullable (suffix `?` on type) or non-nullable (suffix `!`). It also tracks any API that is still using an oblivious reference type (prefix `~` on line). -## [RS0041](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Public members should not use oblivious types - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| -|CodeFix|False| +|CodeFix|True| +--- -### Rule description +## [RS0041](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Public members should not use oblivious types All public members should use either nullable or non-nullable reference types, but no oblivious reference types. -## [RS0048](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Missing shipped or unshipped public API file - |Item|Value| |-|-| |Category|ApiDesign| |Enabled|True| |Severity|Warning| |CodeFix|False| +--- -### Rule description +## [RS0048](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md): Missing shipped or unshipped public API file Public API file '{0}' is missing or not marked as an additional analyzer file +|Item|Value| +|-|-| +|Category|ApiDesign| +|Enabled|True| +|Severity|Warning| +|CodeFix|False| +--- diff --git a/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md b/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md index 7e1b19b88a..168b37f043 100644 --- a/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md +++ b/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md @@ -7,6 +7,7 @@ To get started with the Public API Analyzer: 3. Invoke the codefix on any `RS0016` to add the public APIs to the documented set. You can apply the codefix across the entire project or solution to easily document all APIs at once. Text files `PublicAPI.Shipped.txt` and `PublicAPI.Unshipped.txt` will be added to each project in scope, if they do not already exist. **Configuration:** If you would prefer the public API analyzer to bail out silently for projects with missing public API files, you can do so by setting the following .editorconfig option: + ```ini [*.cs] dotnet_public_api_analyzer.require_api_files = true @@ -47,7 +48,7 @@ At that point, reference types in annotated code will need to be annotated with Any public API that haven't been annotated (i.e. uses an oblivious reference type) will be tracked with a `~` marker. The marker lets you track how many public APIs still lack annotations. For instance, `~C.ObliviousMethod() -> string`. -We recommend to enable [RS0041 warning](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md) if you start with a fresh project or your project has reached 100% annotation on your public API to ensure that all public APIs remain annotated. +We recommend to enable [RS0041 warning](https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md) if you start with a fresh project or your project has reached 100% annotation on your public API to ensure that all public APIs remain annotated. If you are in the process of annotating an existing project, we recommended to disable this warning until you complete the annotation. The rule can be disabled via `.editorconfig` with `dotnet_diagnostic.RS0041.severity = none`. ## Conditional API Differences diff --git a/src/PublicApiAnalyzers/RulesMissingDocumentation.md b/src/PublicApiAnalyzers/RulesMissingDocumentation.md index 8add8039c5..75e0f77588 100644 --- a/src/PublicApiAnalyzers/RulesMissingDocumentation.md +++ b/src/PublicApiAnalyzers/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/Roslyn.Diagnostics.Analyzers/Roslyn.Diagnostics.Analyzers.md b/src/Roslyn.Diagnostics.Analyzers/Roslyn.Diagnostics.Analyzers.md index abfaba1162..a16ee3d4a4 100644 --- a/src/Roslyn.Diagnostics.Analyzers/Roslyn.Diagnostics.Analyzers.md +++ b/src/Roslyn.Diagnostics.Analyzers/Roslyn.Diagnostics.Analyzers.md @@ -2,235 +2,216 @@ ## RS0001: Use 'SpecializedCollections.EmptyEnumerable()' +Use 'SpecializedCollections.EmptyEnumerable()' + |Item|Value| |-|-| |Category|RoslynDiagnosticsPerformance| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Use 'SpecializedCollections.EmptyEnumerable()' +--- ## RS0002: Use 'SpecializedCollections.SingletonEnumerable()' +Use 'SpecializedCollections.SingletonEnumerable()' + |Item|Value| |-|-| |Category|RoslynDiagnosticsPerformance| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Use 'SpecializedCollections.SingletonEnumerable()' +--- ## RS0004: Invoke the correct property to ensure correct use site diagnostics +Invoke the correct property to ensure correct use site diagnostics + |Item|Value| |-|-| |Category|Usage| |Enabled|False| |Severity|Error| |CodeFix|False| - -### Rule description - -Invoke the correct property to ensure correct use site diagnostics +--- ## RS0005: Do not use generic 'CodeAction.Create' to create 'CodeAction' +Do not use generic 'CodeAction.Create' to create 'CodeAction' + |Item|Value| |-|-| |Category|RoslynDiagnosticsPerformance| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Do not use generic 'CodeAction.Create' to create 'CodeAction' +--- ## RS0006: Do not mix attributes from different versions of MEF +Do not mix attributes from different versions of MEF. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Do not mix attributes from different versions of MEF. +--- ## RS0019: 'SymbolDeclaredEvent' must be generated for source symbols +Compilation event queue is required to generate symbol declared events for all declared source symbols. Hence, every source symbol type or one of its base types must generate a symbol declared event. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|False| |Severity|Error| |CodeFix|False| - -### Rule description - -Compilation event queue is required to generate symbol declared events for all declared source symbols. Hence, every source symbol type or one of its base types must generate a symbol declared event. +--- ## RS0023: Parts exported with MEFv2 must be marked with 'SharedAttribute' +Part exported with MEFv2 must be marked with the 'SharedAttribute'. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Part exported with MEFv2 must be marked with the 'SharedAttribute'. +--- ## RS0032: Test exports should not be discoverable +Test exports should not be discoverable. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|False| |Severity|Warning| |CodeFix|True| - -### Rule description - -Test exports should not be discoverable. +--- ## RS0033: Importing constructor should be marked with 'ObsoleteAttribute' +Importing constructor should be marked with 'ObsoleteAttribute'. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Importing constructor should be marked with 'ObsoleteAttribute'. +--- ## RS0034: Exported parts should be marked with 'ImportingConstructorAttribute' +Exported parts should be marked with 'ImportingConstructorAttribute'. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Exported parts should be marked with 'ImportingConstructorAttribute'. +--- ## RS0038: Prefer null literal +Use 'null' instead of 'default' for nullable types. + |Item|Value| |-|-| |Category|RoslynDiagnosticsMaintainability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Use 'null' instead of 'default' for nullable types. +--- ## RS0040: Defaultable types should have defaultable fields +Defaultable types should have defaultable fields. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Defaultable types should have defaultable fields. +--- ## RS0042: Do not copy value +Do not unbox non-copyable value types. + |Item|Value| |-|-| |Category|RoslynDiagnosticsReliability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -Do not unbox non-copyable value types. +--- ## RS0043: Do not call 'GetTestAccessor()' +'GetTestAccessor()' is a helper method reserved for testing. Production code must not call this member. + |Item|Value| |-|-| |Category|RoslynDiagnosticsMaintainability| |Enabled|True| |Severity|Warning| |CodeFix|False| - -### Rule description - -'GetTestAccessor()' is a helper method reserved for testing. Production code must not call this member. +--- ## RS0046: Avoid the 'Opt' suffix +Avoid the 'Opt' suffix in a nullable-enabled code. + |Item|Value| |-|-| |Category|RoslynDiagnosticsDesign| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Avoid the 'Opt' suffix in a nullable-enabled code. +--- ## RS0100: Statements must be placed on their own line +Statements must be placed on their own line + |Item|Value| |-|-| |Category|RoslynDiagnosticsMaintainability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Statements must be placed on their own line +--- ## RS0101: Avoid multiple blank lines +Avoid multiple blank lines + |Item|Value| |-|-| |Category|RoslynDiagnosticsMaintainability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Avoid multiple blank lines +--- ## RS0102: Braces must not have blank lines between them +Braces must not have blank lines between them + |Item|Value| |-|-| |Category|RoslynDiagnosticsMaintainability| |Enabled|True| |Severity|Warning| |CodeFix|True| - -### Rule description - -Braces must not have blank lines between them - +--- diff --git a/src/Roslyn.Diagnostics.Analyzers/RulesMissingDocumentation.md b/src/Roslyn.Diagnostics.Analyzers/RulesMissingDocumentation.md index ffd45f40d1..08d8223541 100644 --- a/src/Roslyn.Diagnostics.Analyzers/RulesMissingDocumentation.md +++ b/src/Roslyn.Diagnostics.Analyzers/RulesMissingDocumentation.md @@ -1,4 +1,4 @@ -## Rules without documentation +# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------| diff --git a/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs b/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs index 927161ce22..6510bad5f2 100644 --- a/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs +++ b/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs @@ -10,6 +10,7 @@ using System.Net; using System.Reflection; using System.Text; +using System.Text.RegularExpressions; using Analyzer.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; @@ -279,10 +280,11 @@ void createAnalyzerDocumentationFile() var builder = new StringBuilder(); - var title = Path.GetFileNameWithoutExtension(analyzerDocumentationFileName); - builder.AppendLine($"# {title}"); + var fileTitle = Path.GetFileNameWithoutExtension(analyzerDocumentationFileName); + builder.AppendLine($"# {fileTitle}"); builder.AppendLine(); + var isFirstEntry = true; foreach (var ruleById in allRulesById) { string ruleId = ruleById.Key; @@ -294,19 +296,18 @@ void createAnalyzerDocumentationFile() ruleIdWithHyperLink = $"[{ruleIdWithHyperLink}]({descriptor.HelpLinkUri})"; } - builder.AppendLine($"## {ruleIdWithHyperLink}: {descriptor.Title}"); - builder.AppendLine(); + var title = descriptor.Title.ToString(CultureInfo.InvariantCulture).Trim(); + // Escape generic arguments to ensure they are not considered as HTML elements + title = Regex.Replace(title, "(<.+?>)", "\\$1"); - builder.AppendLine("|Item|Value|"); - builder.AppendLine("|-|-|"); - builder.AppendLine($"|Category|{descriptor.Category}|"); - builder.AppendLine($"|Enabled|{descriptor.IsEnabledByDefault}|"); - builder.AppendLine($"|Severity|{descriptor.DefaultSeverity}|"); - var hasCodeFix = fixableDiagnosticIds.Contains(descriptor.Id); - builder.AppendLine($"|CodeFix|{hasCodeFix}|"); - builder.AppendLine(); + if (!isFirstEntry) + { + // Add separation line only when reaching next entry to avoid useless empty line at the end + builder.AppendLine(); + } - builder.AppendLine($"### Rule description"); + isFirstEntry = false; + builder.AppendLine($"## {ruleIdWithHyperLink}: {title}"); builder.AppendLine(); var description = descriptor.Description.ToString(CultureInfo.InvariantCulture); @@ -315,11 +316,23 @@ void createAnalyzerDocumentationFile() description = descriptor.MessageFormat.ToString(CultureInfo.InvariantCulture); } - // Replace line breaks with HTML breaks so that new - // lines don't break the markdown table formatting. - description = System.Text.RegularExpressions.Regex.Replace(description, "\r?\n", "
"); + // Double the line breaks to ensure they are rendered properly in markdown + description = Regex.Replace(description, "(\r?\n)", "$1$1"); + // Escape generic arguments to ensure they are not considered as HTML elements + description = Regex.Replace(description, "(<.+?>)", "\\$1"); + description = description.Trim(); + builder.AppendLine(description); builder.AppendLine(); + + builder.AppendLine("|Item|Value|"); + builder.AppendLine("|-|-|"); + builder.AppendLine($"|Category|{descriptor.Category}|"); + builder.AppendLine($"|Enabled|{descriptor.IsEnabledByDefault}|"); + builder.AppendLine($"|Severity|{descriptor.DefaultSeverity}|"); + var hasCodeFix = fixableDiagnosticIds.Contains(descriptor.Id); + builder.AppendLine($"|CodeFix|{hasCodeFix}|"); + builder.AppendLine("---"); } File.WriteAllText(fileWithPath, builder.ToString()); @@ -462,7 +475,7 @@ void createAnalyzerRulesMissingDocumentationFile() var fileWithPath = Path.Combine(directory.FullName, "RulesMissingDocumentation.md"); var builder = new StringBuilder(); - builder.Append(@"## Rules without documentation + builder.Append(@"# Rules without documentation Rule ID | Missing Help Link | Title | --------|-------------------|-------|