Skip to content

Commit 0f120e5

Browse files
authored
Core libraries breaking changes for Preview 6 (#41725)
1 parent 29f0af3 commit 0f120e5

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

docs/core/compatibility/9.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ If you're migrating an app to .NET 9, the breaking changes listed here might aff
2828
| [Adding a ZipArchiveEntry with CompressionLevel sets ZIP central directory header general-purpose bit flags](core-libraries/9.0/compressionlevel-bits.md) | Behavioral change | Preview 5 |
2929
| [API obsoletions with custom diagnostic IDs](core-libraries/9.0/obsolete-apis-with-custom-diagnostics.md) | Source incompatible | Preview 1 |
3030
| [Creating type of array of System.Void not allowed](core-libraries/9.0/type-instance.md) | Behavioral change | Preview 1 |
31+
| [Default `Equals()` and `GetHashCode()` throw for types marked with `InlineArrayAttribute`](core-libraries/9.0/inlinearrayattribute.md) | Behavioral change | Preview 6 |
3132
| [Inline array struct size limit is enforced](core-libraries/9.0/inlinearray-size.md) | Behavioral change | Preview 1 |
3233
| [InMemoryDirectoryInfo prepends rootDir to files](core-libraries/9.0/inmemorydirinfo-prepends-rootdir.md) | Behavioral change | Preview 1 |
3334
| [RuntimeHelpers.GetSubArray returns different type](core-libraries/9.0/getsubarray-return.md) | Behavioral change | Preview 1 |
35+
| [Support for empty environment variables](core-libraries/9.0/empty-env-variable.md) | Behavioral change | Preview 6 |
3436

3537
## Networking
3638

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: "Breaking change: Support for empty environment variables"
3+
description: Learn about the .NET 9 breaking change in core .NET libraries where passing `string.Empty` to `Environment.SetEnvironmentVariable` no longer deletes the environment variable.
4+
ms.date: 07/10/2024
5+
---
6+
# Support for empty environment variables
7+
8+
Support was added to be able to set an environment variable to the empty string using <xref:System.Environment.SetEnvironmentVariable(System.String,System.String)?displayProperty=nameWithType>. As part of this work, the behavior of setting the <xref:System.Diagnostics.ProcessStartInfo.Environment?displayProperty=nameWithType> and <xref:System.Diagnostics.ProcessStartInfo.EnvironmentVariables?displayProperty=nameWithType> properties was changed to be consistent with that of <xref:System.Environment.SetEnvironmentVariable(System.String,System.String)?displayProperty=nameWithType>.
9+
10+
## Previous behavior
11+
12+
Previously:
13+
14+
- Both `Environment.SetEnvironmentVariable("TEST", string.Empty)` and `Environment.SetEnvironmentVariable("TEST", null)` deleted the environment variable.
15+
- Both `ProcessStartInfo.Environment["TEST"] = string.Empty` and `ProcessStartInfo.Environment["TEST"] = null` set the environment variable in the child process to an empty value.
16+
17+
## New behavior
18+
19+
Starting in .NET 9:
20+
21+
- `Environment.SetEnvironmentVariable("TEST", string.Empty)` sets the environment variable value to an empty value. `Environment.SetEnvironmentVariable("TEST", null)` behavior is unchanged, that is, it still deletes the environment variable.
22+
- `ProcessStartInfo.Environment["TEST"] = null` deletes the environment variable. `ProcessStartInfo.Environment["TEST"] = string.Empty` behavior is unchanged, that is, it still sets the environment variable to an empty value.
23+
24+
## Version introduced
25+
26+
.NET 9 Preview 6
27+
28+
## Type of breaking change
29+
30+
This change is a [behavioral change](../../categories.md#behavioral-change).
31+
32+
## Reason for change
33+
34+
Before this change, it wasn't possible to use <xref:System.Environment.SetEnvironmentVariable(System.String,System.String)?displayProperty=nameWithType> to set an environment variable to an empty value, which is a valid environment variable value on all supported platforms.
35+
36+
## Recommended action
37+
38+
To delete an environment variable using <xref:System.Environment.SetEnvironmentVariable(System.String,System.String)?displayProperty=nameWithType>, change your code to pass `null` instead of `string.Empty` as the value argument.
39+
40+
To set the environment variable to an empty value using <xref:System.Diagnostics.ProcessStartInfo.Environment?displayProperty=nameWithType> or <xref:System.Diagnostics.ProcessStartInfo.EnvironmentVariables?displayProperty=nameWithType>, change your code to set these properties to `string.Empty` instead of to `null`.
41+
42+
## Affected APIs
43+
44+
- <xref:System.Environment.SetEnvironmentVariable(System.String,System.String)?displayProperty=fullName>
45+
- <xref:System.Diagnostics.ProcessStartInfo.Environment?displayProperty=fullName>
46+
- <xref:System.Diagnostics.ProcessStartInfo.EnvironmentVariables?displayProperty=fullName>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: "Breaking change: Default `Equals()` and `GetHashCode()` throw for types marked with `InlineArrayAttribute`"
3+
description: Learn about the .NET 9 breaking change in core .NET libraries where the default implementations of `Equals()` and `GetHashCode()` throw an exception for types marked with `InlineArrayAttribute`.
4+
ms.date: 07/10/2024
5+
---
6+
# Default `Equals()` and `GetHashCode()` throw for types marked with `InlineArrayAttribute`
7+
8+
The default behavior for <xref:System.ValueType.Equals(System.Object)> and <xref:System.ValueType.GetHashCode> on types marked with <xref:System.Runtime.CompilerServices.InlineArrayAttribute> is now to throw a <xref:System.NotSupportedException>. Library authors should override these two methods if they're expected to not throw.
9+
10+
## Previous behavior
11+
12+
Previously, the default implementations only used the placeholder `ref` field when computing equality or the hash code.
13+
14+
## New behavior
15+
16+
Starting in .NET 9, a <xref:System.NotSupportedException> is always thrown from the default implementations for <xref:System.ValueType.Equals(System.Object)> and <xref:System.ValueType.GetHashCode> when <xref:System.Runtime.CompilerServices.InlineArrayAttribute> is applied to a type.
17+
18+
## Version introduced
19+
20+
.NET 9 Preview 6
21+
22+
## Type of breaking change
23+
24+
This change is a [behavioral change](../../categories.md#behavioral-change).
25+
26+
## Reason for change
27+
28+
The current behavior is incorrect for both determining equality and computing the hash code, and users are led into a false sense of correctness when calling these functions.
29+
30+
## Recommended action
31+
32+
Library authors should implement both <xref:System.ValueType.Equals(System.Object)> and <xref:System.ValueType.GetHashCode> on all types marked with <xref:System.Runtime.CompilerServices.InlineArrayAttribute>.
33+
34+
## Affected APIs
35+
36+
- <xref:System.ValueType.Equals(System.Object)?displayProperty=fullName>
37+
- <xref:System.ValueType.GetHashCode?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ items:
2020
href: core-libraries/9.0/compressionlevel-bits.md
2121
- name: Creating type of array of System.Void not allowed
2222
href: core-libraries/9.0/type-instance.md
23+
- name: "`Equals`/`GetHashCode` throw for `InlineArrayAttribute` types"
24+
href: core-libraries/9.0/inlinearrayattribute.md
2325
- name: Inline array struct size limit is enforced
2426
href: core-libraries/9.0/inlinearray-size.md
2527
- name: InMemoryDirectoryInfo prepends rootDir to files
2628
href: core-libraries/9.0/inmemorydirinfo-prepends-rootdir.md
2729
- name: RuntimeHelpers.GetSubArray returns different type
2830
href: core-libraries/9.0/getsubarray-return.md
31+
- name: Support for empty environment variables
32+
href: core-libraries/9.0/empty-env-variable.md
2933
- name: Networking
3034
items:
3135
- name: HttpListenerRequest.UserAgent is nullable
@@ -1180,12 +1184,16 @@ items:
11801184
href: core-libraries/9.0/compressionlevel-bits.md
11811185
- name: Creating type of array of System.Void not allowed
11821186
href: core-libraries/9.0/type-instance.md
1187+
- name: "`Equals`/`GetHashCode` throw for `InlineArrayAttribute` types"
1188+
href: core-libraries/9.0/inlinearrayattribute.md
11831189
- name: Inline array struct size limit is enforced
11841190
href: core-libraries/9.0/inlinearray-size.md
11851191
- name: InMemoryDirectoryInfo prepends rootDir to files
11861192
href: core-libraries/9.0/inmemorydirinfo-prepends-rootdir.md
11871193
- name: RuntimeHelpers.GetSubArray returns different type
11881194
href: core-libraries/9.0/getsubarray-return.md
1195+
- name: Support for empty environment variables
1196+
href: core-libraries/9.0/empty-env-variable.md
11891197
- name: .NET 8
11901198
items:
11911199
- name: Activity operation name when null

0 commit comments

Comments
 (0)