Skip to content

Preserve assembly key-token identity in ILAsm attribute type names - #137096

Merged
jkoritzinsky merged 2 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-fixed-buffer-metadata
Nov 7, 2026
Merged

jkoritzinsky merged 2 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-fixed-buffer-metadata

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

Fix managed ILAsm's serialization of assembly identities in structured custom attribute type arguments. The existing code treats every public-key-or-token blob as a full public key, so .publickeytoken is serialized as PublicKey= rather than PublicKeyToken=.

This prevents the C# metadata importer from resolving the System.Int32 element type in FixedBufferAttribute. The RefFieldTests.FixedField_02 fixture consequently produces CS0021 instead of the expected CS0570. Honor AssemblyFlags.PublicKey when constructing the serialized identity; retain the intentionally malformed byref field signature without changing compiler expectations.

Regression coverage includes value and byref fixed-buffer fields, and unsigned, public-key-token, and full-public-key assembly references. This PR contains only the key-token fix and its tests; the independent explicit-valuetype change is not required and is excluded.

Validation:

  • .\build.cmd tools.ilasm -test: passed on Windows x64, 5,790 passed, 3 skipped, 0 failed, with no explicit-valuetype prerequisite.
  • Three new cases failed before the key-token correction and passed afterward.
  • Standalone SDK C# compilation of the fixture's consumer: unfixed managed output produces CS0021; native and corrected managed output produce the expected CS0570. Confirmed CS0570 again after removing the explicit-valuetype prerequisite.
  • The Roslyn test suite was not run, and its checkout was not modified.

Note

This pull request description and code changes were generated with GitHub Copilot.

Honor AssemblyFlags.PublicKey rather than treating every key-or-token blob as a full public key. Preserve malformed byref fixed-buffer fields while allowing importers to resolve their serialized element types.

Regression tests fail before the correction, including after the explicit-valuetype prerequisite, and pass afterward. Windows tools.ilasm: 5802 passed, 3 skipped. Standalone SDK C# consumer reports CS0021 with unfixed output and CS0570 with both native and corrected output.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the assembly identity serialization change.

No open issues 🎉

What changed in this PR

Fixes managed ILAsm’s assembly identity serialization for structured custom attribute type arguments, preserving the distinction between public keys and public key tokens needed for type resolution.

Changes:

  • Uses AssemblyFlags.PublicKey to select the correct assembly identity format.
  • Extends attribute tests to cover unsigned, public-key-token, and full-public-key assembly references.
  • Adds fixed-buffer regression coverage for value and byref fields while preserving their signatures.
File Description
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​FieldTests.cs Tests fixed-buffer element type identity and value/byref field signatures.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​CustomAttributeTests.cs Covers assembly-qualified type names across three key configurations.
src/​tools/​ilasm/​src/​ILAssembler/​EntityRegistry.cs Honors assembly flags when serializing public keys or tokens.

Review effort: Balanced

@jkoritzinsky
jkoritzinsky enabled auto-merge (squash) November 6, 2026 21:48
@jkoritzinsky
jkoritzinsky merged commit 8f82116 into dotnet:main Nov 7, 2026
61 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Nov 7, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants