You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"_csharplang/proposals/lock-object.md": "Special-case how `System.Threading.Lock` interacts with the `lock` keyword by calling its `EnterScope` method. Add static analysis warnings to prevent accidental misuse of the type where possible.",
779
780
"_csharplang/proposals/method-group-natural-type-improvements.md": "This proposal refines the determination of the natural type of a method group by considering candidates scope-by-scope and pruning at each scope.",
780
781
"_csharplang/proposals/params-collections.md": "Allow the `params` modifier on collection types beyond arrays, including `IEnumerable` types.",
782
+
"_csharplang/proposals/ref-unsafe-in-terators-async.md": "This proposal modifies restrictions to enable ref local variables and unsafe blocks in iterators and async methods",
781
783
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "Learn about any breaking changes since the initial release of C# 10",
782
784
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 8.md": "Learn about any breaking changes since the initial release of C# 11",
783
785
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 9.md": "Learn about any breaking changes since the initial release of C# 12",
description: Learn how to build resilient HTTP apps using the Microsoft.Extensions.Http.Resilience NuGet package.
4
4
author: IEvangelist
5
5
ms.author: dapine
6
-
ms.date: 10/20/2023
6
+
ms.date: 07/01/2024
7
7
---
8
8
9
9
# Build resilient HTTP apps: Key development patterns
@@ -81,13 +81,26 @@ The preceding code adds the standard resilience handler to the <xref:System.Net.
81
81
82
82
The default configuration chains five resilience strategies in the following order (from the outermost to the innermost):
83
83
84
-
| Order | Strategy | Description |
85
-
|--:|--|--|
86
-
|**1**| Rate limiter | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. |
87
-
|**2**| Total request timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including retry attempts, doesn't exceed the configured limit. |
88
-
|**3**| Retry | The retry pipeline retries the request in case the dependency is slow or returns a transient error. |
89
-
|**4**| Circuit breaker | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. |
90
-
|**5**| Attempt timeout | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. |
84
+
| Order | Strategy | Description | Defaults |
85
+
|--:|--|--|--|
86
+
|**1**| Rate limiter | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. | Queue: `0`<br>Permit: `1_000`|
87
+
|**2**| Total timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including retry attempts, doesn't exceed the configured limit. | Total timeout: 30s |
88
+
|**3**| Retry | The retry pipeline retries the request in case the dependency is slow or returns a transient error. | Max retries: `3`<br>Backoff: `Exponential`<br>Use jitter: `true`<br>Delay:2s |
89
+
|**4**| Circuit breaker | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. | Failure ratio: 10%<br>Min throughput: `100`<br>Sampling duration: 30s<br>Break duration: 5s |
90
+
|**5**| Attempt timeout | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | Attempt timeout: 10s |
91
+
92
+
#### Retries and circuit breakers
93
+
94
+
The retry and circuit breaker strategies both handle a set of specific HTTP status codes and exceptions. Consider the following HTTP status codes:
95
+
96
+
- HTTP 500 and above (Server errors)
97
+
- HTTP 408 (Request timeout)
98
+
- HTTP 429 (Too many requests)
99
+
100
+
Additionally, these strategies handle the following exceptions:
101
+
102
+
-`HttpRequestException`
103
+
-`TimeoutRejectedException`
91
104
92
105
## Add standard hedging handler
93
106
@@ -108,13 +121,13 @@ The standard hedging uses a pool of circuit breakers to ensure that unhealthy en
108
121
109
122
The preceding code adds the standard hedging handler to the <xref:Microsoft.Extensions.DependencyInjection.IHttpClientBuilder>. The default configuration chains five resilience strategies in the following order (from the outermost to the innermost):
110
123
111
-
| Order | Strategy | Description |
112
-
|--:|--|--|
113
-
|**1**| Total request timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including hedging attempts, doesn't exceed the configured limit. |
114
-
|**2**| Hedging | The hedging strategy executes the requests against multiple endpoints in case the dependency is slow or returns a transient error. Routing is options, by default it just hedges the URL provided by the original <xref:System.Net.Http.HttpRequestMessage>. |
115
-
|**3**| Rate limiter (per endpoint) | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. |
116
-
|**4**| Circuit breaker (per endpoint) | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. |
117
-
|**5**| Attempt timeout (per endpoint) | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. |
124
+
| Order | Strategy | Description | Defaults |
125
+
|--:|--|--|--|
126
+
|**1**| Total request timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including hedging attempts, doesn't exceed the configured limit. | Total timeout: 30s |
127
+
|**2**| Hedging | The hedging strategy executes the requests against multiple endpoints in case the dependency is slow or returns a transient error. Routing is options, by default it just hedges the URL provided by the original <xref:System.Net.Http.HttpRequestMessage>. | Min attempts: `1`<br>Max attempts: `10`<br>Delay: 2s |
128
+
|**3**| Rate limiter (per endpoint) | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. | Queue: `0`<br>Permit: `1_000`|
129
+
|**4**| Circuit breaker (per endpoint) | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. | Failure ratio: 10%<br>Min throughput: `100`<br>Sampling duration: 30s<br>Break duration: 5s |
130
+
|**5**| Attempt timeout (per endpoint) | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | Timeout: 10s |
title: "MSTEST0030: Type containing `[TestMethod]` should be marked with `[TestClass]`"
3
+
description: "Learn about code analysis rule MSTEST0030: Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored."
4
+
ms.date: 07/02/2024
5
+
f1_keywords:
6
+
- MSTEST0030
7
+
- TypeContainingTestMethodShouldBeATestClass
8
+
helpviewer_keywords:
9
+
- TypeContainingTestMethodShouldBeATestClass
10
+
- MSTEST0030
11
+
author: engyebrahim
12
+
ms.author: enjieid
13
+
---
14
+
# MSTEST0030: Type containing `[TestMethod]` should be marked with `[TestClass]`
|**Title**| Type containing `[TestMethod]` should be marked with `[TestClass]`|
20
+
|**Category**| Usage |
21
+
|**Fix is breaking or non-breaking**| Non-breaking |
22
+
|**Enabled by default**| Yes |
23
+
|**Default severity**| Info |
24
+
|**Introduced in version**| 3.5.0 |
25
+
26
+
## Cause
27
+
28
+
Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored.
29
+
30
+
## Rule description
31
+
32
+
MSTest considers test methods only on the context of a test class container (a class marked with [TestClass] or derived attribute) which could lead to some tests being silently ignored. If your class is supposed to represent common test behavior to be executed by children classes, it's recommended to mark the type as abstract to clarify the intent for other developers reading the code.
33
+
34
+
## How to fix violations
35
+
36
+
A non-abstract class contains test methods should be marked with '[TestClass]'.
37
+
38
+
## When to suppress warnings
39
+
40
+
It's safe to suppress the diagnostic if you are sure that your class is being inherited and that the tests declared on this class should only be run in the context of subclasses. Nonetheless, we recommend marking the class as abstract.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/builtin-types/ref-struct.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "ref struct types"
3
3
description: Learn about the ref struct type in C#
4
-
ms.date: 10/12/2022
4
+
ms.date: 06/28/2024
5
5
---
6
6
# `ref` structure types (C# reference)
7
7
@@ -12,9 +12,9 @@ You can use the `ref` modifier in the declaration of a [structure type](struct.m
12
12
- A `ref struct` can't implement interfaces.
13
13
- A `ref struct` can't be boxed to <xref:System.ValueType?displayProperty=nameWithType> or <xref:System.Object?displayProperty=nameWithType>.
14
14
- A `ref struct` can't be a type argument.
15
-
- A `ref struct` variable can't be captured by a [lambda expression](../operators/lambda-expressions.md) or a [local function](../../programming-guide/classes-and-structs/local-functions.md).
16
-
-A `ref struct` variable can't be used in an [`async`](../keywords/async.md) method. However, you can use `ref struct` variables in synchronous methods, for example, in methods that return <xref:System.Threading.Tasks.Task> or <xref:System.Threading.Tasks.Task%601>.
17
-
-A `ref struct` variable can't be used in [iterators](../../iterators.md).
15
+
- A `ref struct` variable can't be captured in a [lambda expression](../operators/lambda-expressions.md) or a [local function](../../programming-guide/classes-and-structs/local-functions.md).
16
+
-Before C# 13,`ref struct`variables can't be used in an `async` method. Beginning with C# 13, a `ref struct`variable can't be used in the same block as the [`await`](../operators/await.md) expression in an [`async`](../keywords/async.md) method. However, you can use `ref struct` variables in synchronous methods, for example, in methods that return <xref:System.Threading.Tasks.Task> or <xref:System.Threading.Tasks.Task%601>.
17
+
-Before C# 13, a `ref struct` variable can't be used in [iterators](../../iterators.md). Beginning with C# 13, `ref struct` types and `ref` locals can be used in iterators, provided they aren't in code segments with the `yield return` statement.
18
18
19
19
You can define a disposable `ref struct`. To do that, ensure that a `ref struct` fits the [disposable pattern](~/_csharplang/proposals/csharp-8.0/using.md#pattern-based-using). That is, it has an instance `Dispose` method, which is accessible, parameterless and has a `void` return type. You can use the [using statement or declaration](../statements/using.md) with an instance of a disposable `ref struct`.
20
20
@@ -34,13 +34,13 @@ Beginning with C# 11, you can declare a `ref` field in a `ref struct`, as the fo
A `ref` field may have the `null` value. Use the <xref:System.Runtime.CompilerServices.Unsafe.IsNullRef%60%601(%60%600@)?displayProperty=nameWithType> method to determine if a `ref` field is `null`.
37
+
A `ref` field can have the `null` value. Use the <xref:System.Runtime.CompilerServices.Unsafe.IsNullRef%60%601(%60%600@)?displayProperty=nameWithType> method to determine if a `ref` field is `null`.
38
38
39
39
You can apply the `readonly` modifier to a `ref` field in the following ways:
40
40
41
41
-`readonly ref`: You can [ref reassign](../operators/assignment-operator.md#ref-assignment) such a field with the `= ref` operator only inside a constructor or an [`init` accessor](../keywords/init.md). You can assign a value with the `=` operator at any point allowed by the field access modifier.
42
-
-`ref readonly`: At any point, you cannot assign a value with the `=` operator to such a field. However, you can ref reassign a field with the `= ref` operator.
43
-
-`readonly ref readonly`: You can only ref reassign such a field in a constructor or an `init` accessor. At any point, you cannot assign a value to the field.
42
+
-`ref readonly`: At any point, you can't assign a value with the `=` operator to such a field. However, you can ref reassign a field with the `= ref` operator.
43
+
-`readonly ref readonly`: You can only ref reassign such a field in a constructor or an `init` accessor. At any point, you can't assign a value to the field.
44
44
45
45
The compiler ensures that a reference stored in a `ref` field doesn't outlive its referent.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/cs1996.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
description: "Compiler Error CS1996"
3
3
title: "Compiler Error CS1996"
4
-
ms.date: 9/12/2022
4
+
ms.date: 7/01/2024
5
5
f1_keywords:
6
6
- "CS1996"
7
7
helpviewer_keywords:
@@ -13,7 +13,7 @@ Cannot await in the body of a lock statement
13
13
14
14
## Example
15
15
16
-
The following sample generates CS1996:
16
+
The following sample generates CS1996:
17
17
18
18
```csharp
19
19
publicclassC
@@ -33,9 +33,11 @@ public class C
33
33
}
34
34
```
35
35
36
+
The preceding code produces the same error with C# 13, as the `await` is in the `lock` statement block.
37
+
36
38
## To correct this error
37
39
38
-
Asynchronous code within a `lock` statement block is hard to implement reliably and even harder to implement in a general sense. The C# compiler doesn't support doing this to avoid emitting code that will be prone to deadlocks. Extracting the asynchronous code from the `lock` statement block will correct this error. For example:
40
+
Asynchronous code within a `lock` statement block is hard to implement reliably and even harder to implement in a general sense. The C# compiler doesn't support doing this to avoid emitting code prone to deadlocks. Extracting the asynchronous code from the `lock` statement block corrects this error. For example:
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/cs4004.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
description: "Compiler Error CS4004"
3
3
title: "Compiler Error CS4004"
4
-
ms.date: 9/12/2022
4
+
ms.date: 07/01/2024
5
5
f1_keywords:
6
6
- "CS4004"
7
7
helpviewer_keywords:
@@ -13,7 +13,7 @@ Cannot await in an unsafe context
13
13
14
14
## Example
15
15
16
-
The following sample generates CS4004:
16
+
The following sample generates CS4004:
17
17
18
18
```csharp
19
19
usingSystem.Threading.Tasks;
@@ -47,11 +47,13 @@ public static class C
47
47
}
48
48
```
49
49
50
+
This code generates an error in C# 13 because the `await` is in the `unsafe` block.
51
+
50
52
The `ReverseText` method naively uses a background task to asynchronously create a new string in reverse order of a given string.
51
53
52
54
## To correct this error
53
55
54
-
Separating the unsafe code from the awaitable code will correct this error. One separation technique is creating a new method for the unsafe code and then calling it from the awaitable code. For example:
56
+
Separating the unsafe code from the awaitable code corrects this error. One separation technique is creating a new method for the unsafe code and then calling it from the awaitable code. For example:
0 commit comments