Skip to content

Commit 05185e4

Browse files
authored
assembly.loadfrom obsoletion (dotnet#42084)
1 parent d33acb6 commit 05185e4

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

docs/core/compatibility/core-libraries/9.0/obsolete-apis-with-custom-diagnostics.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Breaking change: .NET 9 obsoletions with custom IDs"
33
titleSuffix: ""
44
description: Learn about the .NET 9 breaking change in core .NET libraries where some APIs have been marked as obsolete with a custom diagnostic ID.
5-
ms.date: 08/01/2024
5+
ms.date: 08/07/2024
66
---
77
# API obsoletions with non-default diagnostic IDs (.NET 9)
88

@@ -19,6 +19,7 @@ The following table lists the custom diagnostic IDs and their corresponding warn
1919
| [SYSLIB0009](../../../../fundamentals/syslib-diagnostics/syslib0009.md) | <xref:System.Net.AuthenticationManager> is not supported. Methods will no-op or throw <xref:System.PlatformNotSupportedException>. | Warning |
2020
| [SYSLIB0054](../../../../fundamentals/syslib-diagnostics/syslib0054.md) | <xref:System.Threading.Thread.VolatileRead%2A?displayProperty=nameWithType> and <xref:System.Threading.Thread.VolatileWrite%2A?displayProperty=nameWithType> are obsolete. Use <xref:System.Threading.Volatile.Read%2A?displayProperty=nameWithType> or <xref:System.Threading.Volatile.Write%2A?displayProperty=nameWithType> instead. | Warning |
2121
| [SYSLIB0055](../../../../fundamentals/syslib-diagnostics/syslib0055.md) | `AdvSimd.ShiftRightLogicalRoundedNarrowingSaturate*` methods with signed parameters are obsolete. Use the unsigned overloads instead. | Warning |
22+
| [SYSLIB0056](../../../../fundamentals/syslib-diagnostics/syslib0056.md) | `Assembly.LoadFrom` with a custom `AssemblyHashAlgorithm` is obsolete. Use overloads without an `AssemblyHashAlgorithm`. | Warning |
2223
| [SYSLIB0057](../../../../fundamentals/syslib-diagnostics/syslib0057.md) | `X509Certificate2` and `X509Certificate` constructors for binary and file content are obsolete. | Warning |
2324

2425
## Version introduced
@@ -58,6 +59,10 @@ These obsoletions can affect [source compatibility](../../categories.md#source-c
5859
- <xref:System.Runtime.Intrinsics.Arm.AdvSimd.ShiftRightLogicalRoundedNarrowingSaturateUpper(System.Runtime.Intrinsics.Vector64{System.Int16},System.Runtime.Intrinsics.Vector128{System.Int32},System.Byte)?displayProperty=fullName>
5960
- <xref:System.Runtime.Intrinsics.Arm.AdvSimd.ShiftRightLogicalRoundedNarrowingSaturateUpper(System.Runtime.Intrinsics.Vector64{System.Int32},System.Runtime.Intrinsics.Vector128{System.Int64},System.Byte)?displayProperty=fullName>
6061

62+
### SYSLIB0056
63+
64+
- <xref:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm)>
65+
6166
### SYSLIB0057
6267

6368
- <xref:System.Security.Cryptography.X509Certificates.X509Certificate2.%23ctor(System.Byte[])>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Obsolete features in .NET 5+
33
titleSuffix: ""
44
description: Learn about APIs that are marked as obsolete in .NET 5 and later versions that produce SYSLIB compiler warnings.
5-
ms.date: 08/01/2024
5+
ms.date: 08/07/2024
66
---
77

88
# Obsolete features in .NET 5+
@@ -76,6 +76,7 @@ The following table provides an index to the `SYSLIB0XXX` obsoletions in .NET 5+
7676
| [SYSLIB0053](syslib0053.md) | Warning | <xref:System.Security.Cryptography.AesGcm> should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size. |
7777
| [SYSLIB0054](syslib0054.md) | Warning | <xref:System.Threading.Thread.VolatileRead%2A?displayProperty=nameWithType> and <xref:System.Threading.Thread.VolatileWrite%2A?displayProperty=nameWithType> are obsolete. Use <xref:System.Threading.Volatile.Read%2A?displayProperty=nameWithType> or <xref:System.Threading.Volatile.Write%2A?displayProperty=nameWithType> instead. |
7878
| [SYSLIB0055](syslib0055.md) | Warning | `AdvSimd.ShiftRightLogicalRoundedNarrowingSaturate*` methods with signed parameters are obsolete. Use the unsigned overloads instead. |
79+
| [SYSLIB0056](syslib0056.md) | Warning | `Assembly.LoadFrom` with a custom `AssemblyHashAlgorithm` is obsolete. Use overloads without an `AssemblyHashAlgorithm`. |
7980
| [SYSLIB0057](syslib0057.md) | Warning | `X509Certificate2` and `X509Certificate` constructors for binary and file content are obsolete. |
8081

8182
## Suppress warnings
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: SYSLIB0056 warning - Assembly.LoadFrom that takes an AssemblyHashAlgorithm is obsolete
3+
description: Learn about the obsoletion of the overload of Assembly.LoadFrom that takes an AssemblyHashAlgorithm that generates compile-time warning SYSLIB0056.
4+
ms.date: 08/07/2024
5+
f1_keywords:
6+
- SYSLIB0056
7+
---
8+
# SYSLIB0056: Assembly.LoadFrom that takes an AssemblyHashAlgorithm is obsolete
9+
10+
The overload of <xref:System.Reflection.Assembly.LoadFrom%2A?displayProperty=nameWithType> that takes an <xref:System.Configuration.Assemblies.AssemblyHashAlgorithm> is obsolete, starting in .NET 9. Calling it in code generates warning `SYSLIB0056` at compile time.
11+
12+
## Reason for obsoletion
13+
14+
<xref:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm)?displayProperty=nameWithType> unconditionally throws a <xref:System.NotSupportedException>. This is a poor development experience. The overload looks like a valid API until it's used, and it throws at run time. Marking it as obsolete gives the necessary design-time signal to not use it.
15+
16+
## Workaround
17+
18+
Use an overload of <xref:System.Reflection.Assembly.LoadFrom%2A?displayProperty=nameWithType> that doesn't take an <xref:System.Configuration.Assemblies.AssemblyHashAlgorithm>.
19+
20+
## Suppress a warning
21+
22+
If you must use the obsolete APIs, you can suppress the warning in code or in your project file.
23+
24+
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
25+
26+
```csharp
27+
// Disable the warning.
28+
#pragma warning disable SYSLIB0056
29+
30+
// Code that uses obsolete API.
31+
// ...
32+
33+
// Re-enable the warning.
34+
#pragma warning restore SYSLIB0056
35+
```
36+
37+
To suppress all the `SYSLIB0056` warnings in your project, add a `<NoWarn>` property to your project file.
38+
39+
```xml
40+
<Project Sdk="Microsoft.NET.Sdk">
41+
<PropertyGroup>
42+
...
43+
<NoWarn>$(NoWarn);SYSLIB0056</NoWarn>
44+
</PropertyGroup>
45+
</Project>
46+
```
47+
48+
For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings).

docs/navigate/tools-diagnostics/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,8 @@ items:
17741774
href: ../../fundamentals/syslib-diagnostics/syslib0054.md
17751775
- name: SYSLIB0055
17761776
href: ../../fundamentals/syslib-diagnostics/syslib0055.md
1777+
- name: SYSLIB0056
1778+
href: ../../fundamentals/syslib-diagnostics/syslib0056.md
17771779
- name: SYSLIB0057
17781780
href: ../../fundamentals/syslib-diagnostics/syslib0057.md
17791781
- name: Source-generated code

0 commit comments

Comments
 (0)