-
Notifications
You must be signed in to change notification settings - Fork 6k
Document breaking change: Disallow loading non-Explicit types with explicit field offsets #49125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Documents a .NET 10 Preview 4 breaking change enforcing validation that disallows explicit field offsets on non-Explicit layout types, adding a new compatibility article and linking it in the TOC and 10.0 summary table.
- Adds dedicated breaking change doc describing previous/new behavior, exception, guidance.
- Updates 10.0 compatibility index and TOC with the new entry.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
File | Description |
---|---|
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md | New breaking change article detailing the enforced validation and remediation steps. |
docs/core/compatibility/10.0.md | Adds row referencing the new breaking change in the Interop section. |
docs/core/compatibility/toc.yml | Adds TOC entry pointing to the new article. |
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Outdated
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Show resolved
Hide resolved
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gewarren I went back and checked the PR that this refers to. We changed the implementation, and I forgot to update the tags. We don't need a breaking change notice for the change as it is only reachable through IL that is not supported in C#, VB.NET, or F#. |
Summary
This PR documents a breaking change introduced in .NET 10 Preview 4 where the runtime now enforces stricter validation for type layouts. The runtime throws a
TypeLoadException
if a type with non-explicit layout (Auto
orSequential
) specifies explicit field offsets using the[FieldOffset]
attribute.Changes
docs/core/compatibility/interop/10.0/explicit-field-offset-validation.md
- comprehensive breaking change documentationdocs/core/compatibility/10.0.md
- added entry to the Interop sectiondocs/core/compatibility/toc.yml
- added TOC entry for the new documentBreaking Change Details
Previous behavior: The runtime ignored explicit field offsets on types with
Auto
orSequential
layouts, which was non-compliant with the ECMA-335 specification.New behavior: Starting in .NET 10 Preview 4, attempting to load such types throws a
TypeLoadException
.Recommended action: Developers should update their code to use
LayoutKind.Explicit
for types that specify explicit field offsets, or remove the[FieldOffset]
attributes if not required.Example
Fixes #496358
Related Resources
Original prompt
This section details on the original issue you should resolve
<issue_title>[Breaking change]: Disallow loading non-Explicit types with explicit field offsets</issue_title>
<issue_description>### Breaking Change: Disallow loading non-Explicit types with explicit field offsets
Description
Starting in .NET 10 Preview 4, the .NET runtime enforces stricter validation for type layouts. Specifically, the runtime now throws a
TypeLoadException
if a type with a non-explicit layout (e.g.,Auto
orSequential
) specifies explicit field offsets using the[FieldOffset]
attribute. This change aligns the runtime's behavior with the ECMA-335 specification, which only permits explicit field offsets for types with anExplicit
layout.Previously, the runtime ignored explicit field offsets on non-explicit layout types, which could lead to unexpected behavior or incorrect assumptions about memory layout.
This change was introduced in PR dotnet/docs#113500.
Version
This breaking change was introduced in .NET 10 Preview 4.
Previous behavior
In earlier versions of .NET, the runtime ignored explicit field offsets on types with
Auto
orSequential
layouts. For example:The above code would execute without error, and the
[FieldOffset]
attributes would be ignored.New behavior
Starting in .NET 10 Preview 4, the runtime enforces the ECMA-335 specification and throws a
TypeLoadException
if a type withAuto
orSequential
layout specifies explicit field offsets. The following code will now throw an exception:Exception thrown:
Type of breaking change
Reason for change
This change was introduced to align the .NET runtime with the ECMA-335 specification, which explicitly disallows explicit field offsets on types with
Auto
orSequential
layouts. The previous behavior of ignoring these offsets was non-compliant and could lead to unexpected behavior or incorrect assumptions about memory layout.Recommended action
To resolve this issue, developers should update their code to use
LayoutKind.Explicit
for types that specify explicit field offsets. For example:Alternatively, if explicit field offsets are not required, remove the
[FieldOffset]
attributes and rely on the default behavior ofSequential
orAuto
layout.Affected APIs
This change does not directly affect specific APIs but impacts the runtime behavior of types defined with the following attributes:
[StructLayout(LayoutKind.Sequential)]
[StructLayout(LayoutKind.Auto)]
[FieldOffset]
Feature area
Additional resources
For further assistance, please contact .NET Breaking Change Notifications.
Associated WorkItem - 496358</issue_description>
Comments on the Issue (you are @copilot in this section)
Fixes #48897
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Internal previews