Skip to content

Commit fd490f1

Browse files
Merge pull request #45586 from dotnet/main
Merge main into live
2 parents 2c2eb62 + 74663ee commit fd490f1

File tree

5 files changed

+90
-4
lines changed

5 files changed

+90
-4
lines changed

docs/core/compatibility/core-libraries/10.0/obsolete-apis.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Breaking change: .NET 10 obsoletions with custom IDs"
33
titleSuffix: ""
44
description: Learn about the APIs that have been marked as obsolete in .NET 10 with a custom diagnostic ID.
5-
ms.date: 01/14/2025
5+
ms.date: 03/28/2025
66
ai-usage: ai-assisted
77
---
88
# API obsoletions with non-default diagnostic IDs (.NET 10)
@@ -20,6 +20,7 @@ The following table lists the custom diagnostic IDs and their corresponding warn
2020
| [SYSLIB0058](../../../../fundamentals/syslib-diagnostics/syslib0058.md) | The `KeyExchangeAlgorithm`, `KeyExchangeStrength`, `CipherAlgorithm`, `CipherAlgorithmStrength`, `HashAlgorithm`, and `HashStrength` properties of <xref:System.Net.Security.SslStream> are obsolete. Use <xref:System.Net.Security.SslStream.NegotiatedCipherSuite> instead. | Warning |
2121
| [SYSLIB0059](../../../../fundamentals/syslib-diagnostics/syslib0059.md) | <xref:Microsoft.Win32.SystemEvents.EventsThreadShutdown?displayProperty=nameWithType> callbacks aren't run before the process exits. Use <xref:System.AppDomain.ProcessExit?displayProperty=nameWithType> instead. | Warning |
2222
| [SYSLIB0060](../../../../fundamentals/syslib-diagnostics/syslib0060.md) | <xref:System.Security.Cryptography.Rfc2898DeriveBytes?displayProperty=nameWithType> constructors are obsolete. Use <xref:System.Security.Cryptography.Rfc2898DeriveBytes.Pbkdf2*?displayProperty=nameWithType> instead. | Warning |
23+
| [SYSLIB0061](../../../../fundamentals/syslib-diagnostics/syslib0061.md) | <xref:System.Linq.Queryable.MaxBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=nameWithType> and <xref:System.Linq.Queryable.MinBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=nameWithType> taking an `IComparer<TSource>` are obsolete. Use the new ones that take an `IComparer<TKey>`. | Warning |
2324

2425
## Version introduced
2526

@@ -58,6 +59,11 @@ These obsoletions can affect [source compatibility](../../categories.md#source-c
5859
- <xref:System.Security.Cryptography.Rfc2898DeriveBytes?displayProperty=fullName>
5960
- <xref:System.Security.Cryptography.Rfc2898DeriveBytes.Pbkdf2*?displayProperty=fullName>
6061

62+
### SYSLIB0061
63+
64+
- <xref:System.Linq.Queryable.MaxBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=fullName>
65+
- <xref:System.Linq.Queryable.MinBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=fullName>
66+
6167
## See also
6268

6369
- [API obsoletions with non-default diagnostic IDs (.NET 9)](../9.0/obsolete-apis-with-custom-diagnostics.md)

docs/core/testing/microsoft-testing-platform-extensions-diagnostics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ To configure the hang dump file generation, use the following options:
6464
| Option | Description |
6565
|--|--|
6666
| `--hangdump` | Generates a dump file in case the test host process hangs. |
67-
| `-⁠-hangdump-filename` | Specifies the file name of the dump. |
67+
| `-⁠-hangdump-filename` | Specifies the file name of the dump. |
6868
| `--hangdump-timeout` | Specifies the timeout after which the dump is generated. The timeout value is specified in one of the following formats:<br/>`1.5h`, `1.5hour`, `1.5hours`<br/>`90m`, `90min`, `90minute`, `90minutes`<br/>`5400s`, `5400sec`, `5400second`, `5400seconds`. Defaults to `30m` (30 minutes). |
6969
| `--hangdump-type` | Specifies the type of the dump. Valid values are `Mini`, `Heap`, `Triage`, `Full`. Defaults as `Full`. For more information, see [Types of mini dumps](../diagnostics/collect-dumps-crash.md#types-of-mini-dumps). |

docs/fundamentals/syslib-diagnostics/obsoletions-overview.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you encounter build warnings or errors due to usage of an obsolete API, follo
2020
The following table provides an index to the `SYSLIB0XXX` obsoletions in .NET 5+.
2121

2222
| Diagnostic ID | Warning or error | Description |
23-
| - | - |
23+
|---------------|------------------|-------------|
2424
| [SYSLIB0001](syslib0001.md) | Warning | The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead. |
2525
| [SYSLIB0002](syslib0002.md) | Error | <xref:System.Security.Permissions.PrincipalPermissionAttribute> is not honored by the runtime and must not be used. |
2626
| [SYSLIB0003](syslib0003.md) | Warning | Code access security (CAS) is not supported or honored by the runtime. |
@@ -78,9 +78,10 @@ The following table provides an index to the `SYSLIB0XXX` obsoletions in .NET 5+
7878
| [SYSLIB0055](syslib0055.md) | Warning | `AdvSimd.ShiftRightLogicalRoundedNarrowingSaturate*` methods with signed parameters are obsolete. Use the unsigned overloads instead. |
7979
| [SYSLIB0056](syslib0056.md) | Warning | `Assembly.LoadFrom` with a custom `AssemblyHashAlgorithm` is obsolete. Use overloads without an `AssemblyHashAlgorithm`. |
8080
| [SYSLIB0057](syslib0057.md) | Warning | `X509Certificate2` and `X509Certificate` constructors for binary and file content are obsolete. |
81-
| SYSLIB0058 | Warning | The `KeyExchangeAlgorithm`, `KeyExchangeStrength`, `CipherAlgorithm`, `CipherAlgorithmStrength`, `HashAlgorithm`, and `HashStrength` properties of <xref:System.Net.Security.SslStream> are obsolete. Use <xref:System.Net.Security.SslStream.NegotiatedCipherSuite> instead. |
81+
| [SYSLIB0058](syslib0058.md) | Warning | The `KeyExchangeAlgorithm`, `KeyExchangeStrength`, `CipherAlgorithm`, `CipherAlgorithmStrength`, `HashAlgorithm`, and `HashStrength` properties of <xref:System.Net.Security.SslStream> are obsolete. Use <xref:System.Net.Security.SslStream.NegotiatedCipherSuite> instead. |
8282
| [SYSLIB0059](syslib0059.md) | Warning | <xref:Microsoft.Win32.SystemEvents.EventsThreadShutdown?displayProperty=nameWithType> callbacks aren't run before the process exits. Use <xref:System.AppDomain.ProcessExit?displayProperty=nameWithType> instead. |
8383
| [SYSLIB0060](syslib0060.md) | Warning | Constructors on <xref:System.Security.Cryptography.Rfc2898DeriveBytes?displayProperty=nameWithType> are obsolete. Use <xref:System.Security.Cryptography.Rfc2898DeriveBytes.Pbkdf2%2A?displayProperty=nameWithType> instead. |
84+
| [SYSLIB0061](syslib0061.md) | Warning | The `Queryable` <xref:System.Linq.Queryable.MaxBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=nameWithType> and <xref:System.Linq.Queryable.MinBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=nameWithType> taking an `IComparer<TSource>` are obsolete. Use the new ones that take an `IComparer<TKey>`. |
8485

8586
## Suppress warnings
8687

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: SYSLIB0061 warning - System.Linq.Queryable.MaxBy and System.Linq.Queryable.MinBy accepting an IComparer\<TSource\> are obsolete.
3+
description: Learn about the obsoletion of some MaxBy and MinBy extension methods. Use of these extension methods generates compile-time warning SYSLIB0061.
4+
ms.date: 03/31/2025
5+
f1_keywords:
6+
- SYSLIB0061
7+
---
8+
# SYSLIB0061: System.Linq.Queryable.MaxBy and System.Linq.Queryable.MinBy taking an IComparer\<TSource\> are obsolete.
9+
10+
Starting in .NET 10, the two extension methods <xref:System.Linq.Queryable.MaxBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=fullName> and <xref:System.Linq.Queryable.MinBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=fullName> that accept an `IComparer<TSource>` are obsolete. Please use the newly added overloads that accept an `IComparer<TKey>` instead.
11+
12+
Calling these old extension methods in code generates warning `SYSLIB0061` at compile time and typically generates a <xref:System.IndexOutOfRangeException?displayName=nameWithType> at runtime.
13+
14+
## Reason for obsoletion
15+
16+
The original `MaxBy` and `MinBy` accepting an `IComparer<T>? comparer` expression parameter were incorrectly implemented using the generic type `TSource` for the `IComparer<T>? comparer` type parameter. This is incorrect because the values passed to the <xref:System.Collections.Generic.Comparer`1.Compare(`0,`0)?displayProperty=nameWithType> method are selected by the `Expression<Func<TSource, TKey>> keySelector` expression parameter, thus the extracted value is of generic type `TKey`.
17+
18+
### Note
19+
20+
This would previously work only if `TSource` and `TKey` were actually the same constructed type. If the types were distinct then a runtime _<xref:System.IndexOutOfRangeException>: Index was outside the bounds of the array._ would be thrown because the needed extension method for `IQueryable<TSource> source` could not be found (for example in <xref:System.Linq.Enumerable.MaxBy*>).
21+
22+
## Workaround
23+
24+
Use the newly added `MaxBy` or `MinBy` method that accepts an `IComparer<TKey>? comparer` parameter. These will not throw an exception.
25+
26+
For example:
27+
28+
```csharp
29+
// This worked correctly since TKey and TSource are both int.
30+
Enumerable.Range(1, 10)
31+
.AsQueryable()
32+
.MaxBy(key => (0 - key), Comparer<int>.Default);
33+
34+
// This would throw since TKey is string but TSource is int
35+
// and will trigger the obsoletion warning now and would
36+
// throw an exeception at runtime.
37+
Enumerable.Range(1, 10)
38+
.AsQueryable()
39+
.MaxBy(key => key.ToString(), Comparer<int>.Default);
40+
41+
// This previously would not compile before to the addition of
42+
// the new methods since TKey is string and TSource is int.
43+
// It will now compile and execute correctly.
44+
Enumerable.Range(1, 10)
45+
.AsQueryable()
46+
.MaxBy(key => key.ToString(), Comparer<string>.Default);
47+
```
48+
49+
## Suppress a warning
50+
51+
If you must use the obsolete API, you can suppress the warning in code or in your project file.
52+
53+
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
54+
55+
```csharp
56+
// Disable the warning.
57+
#pragma warning disable SYSLIB0061
58+
59+
// Code that uses obsolete API.
60+
// ...
61+
62+
// Re-enable the warning.
63+
#pragma warning restore SYSLIB0061
64+
```
65+
66+
To suppress all the `SYSLIB0061` warnings in your project, add a `<NoWarn>` property to your project file.
67+
68+
```xml
69+
<Project Sdk="Microsoft.NET.Sdk">
70+
<PropertyGroup>
71+
...
72+
<NoWarn>$(NoWarn);SYSLIB0061</NoWarn>
73+
</PropertyGroup>
74+
</Project>
75+
```
76+
77+
For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings).

docs/navigate/tools-diagnostics/toc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,8 @@ items:
18431843
href: ../../fundamentals/syslib-diagnostics/syslib0059.md
18441844
- name: SYSLIB0060
18451845
href: ../../fundamentals/syslib-diagnostics/syslib0060.md
1846+
- name: SYSLIB0061
1847+
href: ../../fundamentals/syslib-diagnostics/syslib0061.md
18461848
- name: Experimental features
18471849
items:
18481850
- name: Overview

0 commit comments

Comments
 (0)