Skip to content

Commit 344430c

Browse files
authored
code analysis updates for .net 10 ga (#49662)
1 parent ba1e707 commit 344430c

File tree

319 files changed

+355
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+355
-347
lines changed

docs/fundamentals/code-analysis/overview.md

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Code analysis in .NET
33
titleSuffix: ""
44
description: Learn about source code analysis in the .NET SDK.
5-
ms.date: 09/30/2025
5+
ms.date: 11/05/2025
66
ms.topic: overview
77
ms.custom: updateeachrelease
88
helpviewer_keywords:
@@ -24,6 +24,41 @@ If rule violations are found by an analyzer, they're reported as a suggestion, w
2424
2525
### Enabled rules
2626

27+
# [.NET 10](#tab/net-10)
28+
29+
The following rules are enabled, by default, as errors or warnings in .NET 10. Additional rules are enabled as suggestions.
30+
31+
| Diagnostic ID | Category | Severity | Version added | Description |
32+
|-----------------------------------|------------------|----------|---------------|---------------------------------|
33+
| [CA1416](quality-rules/ca1416.md) | Interoperability | Warning | .NET 5 | Validate platform compatibility |
34+
| [CA1417](quality-rules/ca1417.md) | Interoperability | Warning | .NET 5 | Do not use `OutAttribute` on string parameters for P/Invokes |
35+
| [CA1418](quality-rules/ca1418.md) | Interoperability | Warning | .NET 6 | Use valid platform string |
36+
| [CA1420](quality-rules/ca1420.md) | Interoperability | Warning | .NET 7 | Using features that require runtime marshalling when it's disabled will result in run-time exceptions |
37+
| [CA1422](quality-rules/ca1422.md) | Interoperability | Warning | .NET 7 | Validate platform compatibility |
38+
| [CA1831](quality-rules/ca1831.md) | Performance | Warning | .NET 5 | Use `AsSpan` instead of range-based indexers for string when appropriate |
39+
| [CA1856](quality-rules/ca1856.md) | Performance | Error | .NET 8 | Incorrect usage of `ConstantExpected` attribute |
40+
| [CA1857](quality-rules/ca1857.md) | Performance | Warning | .NET 8 | A constant is expected for the parameter |
41+
| [CA2013](quality-rules/ca2013.md) | Reliability | Warning | .NET 5 | Do not use `ReferenceEquals` with value types |
42+
| [CA2014](quality-rules/ca2014.md) | Reliability | Warning | .NET 5 | Do not use `stackalloc` in loops |
43+
| [CA2015](quality-rules/ca2015.md) | Reliability | Warning | .NET 5 | Do not define finalizers for types derived from <xref:System.Buffers.MemoryManager%601> |
44+
| [CA2017](quality-rules/ca2017.md) | Reliability | Warning | .NET 6 | Parameter count mismatch |
45+
| [CA2018](quality-rules/ca2018.md) | Reliability | Warning | .NET 6 | The `count` argument to `Buffer.BlockCopy` should specify the number of bytes to copy |
46+
| [CA2021](quality-rules/ca2021.md) | Reliability | Warning | .NET 8 | Do not call `Enumerable.Cast<T>` or `Enumerable.OfType<T>` with incompatible types |
47+
| [CA2022](quality-rules/ca2022.md) | Reliability | Warning | .NET 9 | Avoid inexact read with `Stream.Read` |
48+
| [CA2023](quality-rules/ca2023.md) | Reliability | Warning | .NET 10 | Invalid braces in message template |
49+
| [CA2200](quality-rules/ca2200.md) | Usage | Warning | .NET 5 | Rethrow to preserve stack details |
50+
| [CA2247](quality-rules/ca2247.md) | Usage | Warning | .NET 5 | Argument passed to `TaskCompletionSource` constructor should be <xref:System.Threading.Tasks.TaskCreationOptions> enum instead of <xref:System.Threading.Tasks.TaskContinuationOptions> |
51+
| [CA2252](quality-rules/ca2252.md) | Usage | Error | .NET 6 | Opt in to preview features |
52+
| [CA2255](quality-rules/ca2255.md) | Usage | Warning | .NET 6 | The `ModuleInitializer` attribute should not be used in libraries |
53+
| [CA2256](quality-rules/ca2256.md) | Usage | Warning | .NET 6 | All members declared in parent interfaces must have an implementation in a `DynamicInterfaceCastableImplementation`-attributed interface |
54+
| [CA2257](quality-rules/ca2257.md) | Usage | Warning | .NET 6 | Members defined on an interface with the `DynamicInterfaceCastableImplementationAttribute` should be `static` |
55+
| [CA2258](quality-rules/ca2258.md) | Usage | Warning | .NET 6 | Providing a `DynamicInterfaceCastableImplementation` interface in Visual Basic is unsupported |
56+
| [CA2259](quality-rules/ca2259.md) | Usage | Warning | .NET 7 | `ThreadStatic` only affects static fields |
57+
| [CA2260](quality-rules/ca2260.md) | Usage | Warning | .NET 7 | Use correct type parameter |
58+
| [CA2261](quality-rules/ca2261.md) | Usage | Warning | .NET 8 | Do not use `ConfigureAwaitOptions.SuppressThrowing` with `Task<TResult>` |
59+
| [CA2264](quality-rules/ca2264.md) | Usage | Warning | .NET 9 | Do not pass a non-nullable value to `ArgumentNullException.ThrowIfNull` |
60+
| [CA2265](quality-rules/ca2265.md) | Usage | Warning | .NET 9 | Do not compare `Span<T>` to `null` or `default` |
61+
2762
# [.NET 9](#tab/net-9)
2863

2964
The following rules are enabled, by default, as errors or warnings in .NET 9. Additional rules are enabled as suggestions.
@@ -89,38 +124,11 @@ The following rules are enabled, by default, as errors or warnings in .NET 8. Ad
89124
| [CA2260](quality-rules/ca2260.md) | Usage | Warning | .NET 7 | Use correct type parameter |
90125
| [CA2261](quality-rules/ca2261.md) | Usage | Warning | .NET 8 | Do not use `ConfigureAwaitOptions.SuppressThrowing` with `Task<TResult>` |
91126

92-
# [.NET 7](#tab/net-7)
93-
94-
The following rules are enabled, by default, as errors or warnings in .NET 7. Additional rules are enabled as suggestions.
95-
96-
| Diagnostic ID | Category | Severity | Description |
97-
| - | - | - | - |
98-
| [CA1416](quality-rules/ca1416.md) | Interoperability | Warning | Validate platform compatibility |
99-
| [CA1417](quality-rules/ca1417.md) | Interoperability | Warning | Do not use `OutAttribute` on string parameters for P/Invokes |
100-
| [CA1418](quality-rules/ca1418.md) | Interoperability | Warning | Use valid platform string |
101-
| [CA1420](quality-rules/ca1420.md) | Interoperability | Warning | Using features that require runtime marshalling when it's disabled will result in run-time exceptions |
102-
| [CA1422](quality-rules/ca1422.md) | Interoperability | Warning | Validate platform compatibility |
103-
| [CA1831](quality-rules/ca1831.md) | Performance | Warning | Use `AsSpan` instead of range-based indexers for string when appropriate |
104-
| [CA2013](quality-rules/ca2013.md) | Reliability | Warning | Do not use `ReferenceEquals` with value types |
105-
| [CA2014](quality-rules/ca2014.md) | Reliability | Warning | Do not use `stackalloc` in loops |
106-
| [CA2015](quality-rules/ca2015.md) | Reliability | Warning | Do not define finalizers for types derived from <xref:System.Buffers.MemoryManager%601> |
107-
| [CA2017](quality-rules/ca2017.md) | Reliability | Warning | Parameter count mismatch |
108-
| [CA2018](quality-rules/ca2018.md) | Reliability | Warning | The `count` argument to `Buffer.BlockCopy` should specify the number of bytes to copy |
109-
| [CA2200](quality-rules/ca2200.md) | Usage | Warning | Rethrow to preserve stack details |
110-
| [CA2247](quality-rules/ca2247.md) | Usage | Warning | Argument passed to `TaskCompletionSource` constructor should be <xref:System.Threading.Tasks.TaskCreationOptions> enum instead of <xref:System.Threading.Tasks.TaskContinuationOptions> |
111-
| [CA2252](quality-rules/ca2252.md) | Usage | Error | Opt in to preview features |
112-
| [CA2255](quality-rules/ca2255.md) | Usage | Warning | The `ModuleInitializer` attribute should not be used in libraries |
113-
| [CA2256](quality-rules/ca2256.md) | Usage | Warning | All members declared in parent interfaces must have an implementation in a `DynamicInterfaceCastableImplementation`-attributed interface |
114-
| [CA2257](quality-rules/ca2257.md) | Usage | Warning | Members defined on an interface with the `DynamicInterfaceCastableImplementationAttribute` should be `static` |
115-
| [CA2258](quality-rules/ca2258.md) | Usage | Warning | Providing a `DynamicInterfaceCastableImplementation` interface in Visual Basic is unsupported |
116-
| [CA2259](quality-rules/ca2259.md) | Usage | Warning | `ThreadStatic` only affects static fields |
117-
| [CA2260](quality-rules/ca2260.md) | Usage | Warning | Use correct type parameter |
118-
119127
---
120128

121129
You can change the severity of these rules to disable them or elevate them to errors. You can also [enable more rules](#enable-additional-rules).
122130

123-
- For a list of rules that are included with each .NET SDK version, see [Analyzer releases](https://github.com/dotnet/roslyn-analyzers/blob/main/src/NetAnalyzers/Core/AnalyzerReleases.Shipped.md).
131+
- For a list of rules that are included with each .NET SDK version, see [Analyzer releases](https://github.com/dotnet/sdk/blob/main/src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/AnalyzerReleases.Shipped.md).
124132
- For a list of all the code quality rules, see [Code quality rules](quality-rules/index.md).
125133

126134
### Enable additional rules

docs/fundamentals/code-analysis/quality-rules/ca1000.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dev_langs:
2222
| **Title** | Do not declare static members on generic types |
2323
| **Category** | [Design](design-warnings.md) |
2424
| **Fix is breaking or non-breaking** | Breaking |
25-
| **Enabled by default in .NET 9** | No |
25+
| **Enabled by default in .NET 10** | No |
2626

2727
## Cause
2828

docs/fundamentals/code-analysis/quality-rules/ca1001.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dev_langs:
2222
| **Title** | Types that own disposable fields should be disposable |
2323
| **Category** | [Design](design-warnings.md) |
2424
| **Fix is breaking or non-breaking** | Non-breaking - If the type is not visible outside the assembly.<br/><br/>Breaking - If the type is visible outside the assembly. |
25-
| **Enabled by default in .NET 9** | No |
25+
| **Enabled by default in .NET 10** | No |
2626

2727
## Cause
2828

docs/fundamentals/code-analysis/quality-rules/ca1002.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dev_langs:
2121
| **Title** | Do not expose generic lists |
2222
| **Category** | [Design](design-warnings.md) |
2323
| **Fix is breaking or non-breaking** | Breaking |
24-
| **Enabled by default in .NET 9** | No |
24+
| **Enabled by default in .NET 10** | No |
2525

2626
## Cause
2727

docs/fundamentals/code-analysis/quality-rules/ca1003.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dev_langs:
2222
| **Title** | Use generic event handler instances |
2323
| **Category** | [Design](design-warnings.md) |
2424
| **Fix is breaking or non-breaking** | Breaking |
25-
| **Enabled by default in .NET 9** | No |
25+
| **Enabled by default in .NET 10** | No |
2626

2727
## Cause
2828

docs/fundamentals/code-analysis/quality-rules/ca1005.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dev_langs:
2121
| **Title** | Avoid excessive parameters on generic types |
2222
| **Category** | [Design](design-warnings.md) |
2323
| **Fix is breaking or non-breaking** | Breaking |
24-
| **Enabled by default in .NET 9** | No |
24+
| **Enabled by default in .NET 10** | No |
2525

2626
## Cause
2727

docs/fundamentals/code-analysis/quality-rules/ca1008.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dev_langs:
2222
| **Title** | Enums should have zero value |
2323
| **Category** | [Design](design-warnings.md) |
2424
| **Fix is breaking or non-breaking** | Non-breaking - When you're prompted to add a `None` value to a non-flag enumeration. Breaking - When you're prompted to rename or remove any enumeration values. |
25-
| **Enabled by default in .NET 9** | No |
25+
| **Enabled by default in .NET 10** | No |
2626

2727
## Cause
2828

docs/fundamentals/code-analysis/quality-rules/ca1010.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ms.author: gewarren
2121
| **Title** | Collections should implement generic interface |
2222
| **Category** | [Design](design-warnings.md) |
2323
| **Fix is breaking or non-breaking** | Non-breaking |
24-
| **Enabled by default in .NET 9** | No |
24+
| **Enabled by default in .NET 10** | No |
2525

2626
## Cause
2727

docs/fundamentals/code-analysis/quality-rules/ca1012.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dev_langs:
2121
| **Title** | Abstract types should not have public constructors |
2222
| **Category** | [Design](design-warnings.md) |
2323
| **Fix is breaking or non-breaking** | Non-breaking |
24-
| **Enabled by default in .NET 9** | No |
24+
| **Enabled by default in .NET 10** | No |
2525

2626
## Cause
2727

docs/fundamentals/code-analysis/quality-rules/ca1014.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dev_langs:
2222
| **Title** | Mark assemblies with CLSCompliantAttribute |
2323
| **Category** | [Design](design-warnings.md) |
2424
| **Fix is breaking or non-breaking** | Non-breaking |
25-
| **Enabled by default in .NET 9** | No |
25+
| **Enabled by default in .NET 10** | No |
2626

2727
## Cause
2828

0 commit comments

Comments
 (0)