Document InlineArrayAttribute is the correct approach for fixed-size buffers#50898
Merged
AaronRobinsonMSFT merged 7 commits intoJul 7, 2026
Merged
Conversation
Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement user suggestion from issue 112104
Document InlineArrayAttribute as the correct approach for fixed-size buffers
Jan 6, 2026
AaronRobinsonMSFT
approved these changes
Jul 7, 2026
Member
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the native interop documentation to steer readers away from using StructLayoutAttribute.Size as a managed fixed-size buffer mechanism, and to point them to C# inline arrays (InlineArrayAttribute) as the correct approach.
Changes:
- Added a new “Fixed-size buffers and inline arrays” section to explain why
StructLayoutAttribute.Sizecan be unsafe for managed fixed-size buffers and to recommendInlineArrayAttribute. - Updated the interop attributes reference table to cross-reference
InlineArrayAttributefrom theStructLayoutAttributeentry.
Show a summary per file
| File | Description |
|---|---|
| docs/standard/native-interop/customize-struct-marshalling.md | Adds guidance and examples for fixed-size buffers, recommending inline arrays over StructLayoutAttribute.Size. |
| docs/standard/native-interop/apply-interop-attributes.md | Updates the StructLayoutAttribute table entry to point readers toward inline arrays for fixed-size buffers. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 3
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Updated comment to clarify memory allocation issue.
AaronRobinsonMSFT
approved these changes
Jul 7, 2026
gewarren
approved these changes
Jul 7, 2026
jkotas
reviewed
Jul 7, 2026
jkotas
reviewed
Jul 7, 2026
jkotas
reviewed
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes dotnet/runtime#112104
Users attempting to use
StructLayoutAttribute.Sizeto create fixed-size buffers encounter memory corruption because theSizeproperty only affects unmanaged layout, not managed memory allocation for non-blittable types.Changes
customize-struct-marshalling.md: Added "Fixed-size buffers and inline arrays" section
StructLayoutAttribute.Sizefor fixed-size buffersInlineArrayAttributeapply-interop-attributes.md: Added cross-reference to
InlineArrayAttributein theStructLayoutAttributetable entryExample
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Internal previews