Skip to content

Commit 75ef2aa

Browse files
authored
Document InlineArray explicit Size breaking change for .NET 10 (#47906)
1 parent 6093fbe commit 75ef2aa

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
4848
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
4949
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
5050
| [.NET runtime no longer provides default SIGTERM signal handler](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change | Preview 5 |
51+
| [Explicit struct Size disallowed with InlineArray](core-libraries/10.0/inlinearray-explicit-size-disallowed.md) | Binary incompatible | Preview 7 |
5152
| [System.Linq.AsyncEnumerable included in core libraries](core-libraries/10.0/asyncenumerable.md) | Source incompatible | Preview 1 |
5253
| [YMM embedded rounding removed from AVX10.2](core-libraries/10.0/ymm-embedded-rounding.md) | Behavioral change | Preview 5 |
5354

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: "Breaking change: Specifying explicit struct Size disallowed with InlineArray"
3+
description: "Learn about the breaking change in .NET 10 where specifying explicit Size to a struct decorated with InlineArrayAttribute now throws TypeLoadException."
4+
ms.date: 08/08/2025
5+
ai-usage: ai-assisted
6+
---
7+
8+
# Specifying explicit struct Size disallowed with InlineArray
9+
10+
Applying explicit `Size` to a struct decorated with <xref:System.Runtime.CompilerServices.InlineArrayAttribute> is ambiguous and no longer supported in the type loader. Previously, specifying explicit `Size` would result in implementation-specific behavior that might or might not match user expectations.
11+
12+
## Version introduced
13+
14+
.NET 10 Preview 7
15+
16+
## Previous behavior
17+
18+
Previously, specifying <xref:System.Runtime.InteropServices.StructLayoutAttribute.Size> on a struct decorated with <xref:System.Runtime.CompilerServices.InlineArrayAttribute> was allowed, but resulted in implementation-specific behavior that might or might not match user expectations.
19+
20+
```csharp
21+
[InlineArray(8)]
22+
[StructLayout(LayoutKind.Explicit, Size=32)]
23+
struct Int8InlineArray
24+
{
25+
private int _value;
26+
}
27+
```
28+
29+
## New behavior
30+
31+
Starting in .NET 10, specifying <xref:System.Runtime.InteropServices.StructLayoutAttribute.Size> on a struct decorated with <xref:System.Runtime.CompilerServices.InlineArrayAttribute> is disallowed. If you attempt to create an instance of such a struct, you'll get a <xref:System.TypeLoadException>.
32+
33+
## Type of breaking change
34+
35+
This change can affect [binary compatibility](../../categories.md#binary-compatibility).
36+
37+
## Reason for change
38+
39+
Specifying <xref:System.Runtime.InteropServices.StructLayoutAttribute.Size> for an inline array struct is ambiguous and any interpretation would contradict the specification.
40+
41+
## Recommended action
42+
43+
In the unlikely case you need to specify explicit size either for the array element or for the whole inline array, introduce a struct wrapping the element type or the whole array type. In the layout of the wrapper, specify <xref:System.Runtime.InteropServices.StructLayoutAttribute.Size> accordingly.
44+
45+
## Affected APIs
46+
47+
- Type loader

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ items:
5454
href: core-libraries/10.0/maccatalyst-version-normalization.md
5555
- name: No default SIGTERM signal handler
5656
href: core-libraries/10.0/sigterm-signal-handler.md
57+
- name: Explicit struct Size disallowed with InlineArray
58+
href: core-libraries/10.0/inlinearray-explicit-size-disallowed.md
5759
- name: System.Linq.AsyncEnumerable included in core libraries
5860
href: core-libraries/10.0/asyncenumerable.md
5961
- name: YMM embedded rounding removed from AVX10.2

0 commit comments

Comments
 (0)