Skip to content

Fix core-library type resolution in managed ilasm - #136935

Merged
jkoritzinsky merged 2 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-system-object-base-regression
Nov 4, 2026
Merged

jkoritzinsky merged 2 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-system-object-base-regression

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

Managed ilasm can emit a base on a core library's System.Object and introduce an unwanted mscorlib reference. This prevents Roslyn from recognizing the generated netstandard reference assembly as a core library, resulting in CS0518 errors for predefined types.

Follow native ilasm's root-object rule by leaving the recognized core-library System.Object without a base, including explicit and repeated declarations. Use local resolution for implicit bases, unqualified well-known types, and generated debug attributes in core-library mode. Preserve ordinary assemblies' external core-library lookup and explicitly authored assembly references.

Regression coverage checks nil root bases, zero implicit AssemblyRefs, local base and signature handles, debug attributes, value-type validation, and external-reference boundaries.

Validation:

  • .\build.cmd tools.ilasm -test: passed, 5,786 passed / 3 skipped / 0 failed.
  • New root-base and zero-reference cases failed against the corresponding unfixed implementations and passed with the fixes.
  • Reassembled the full netstandard.library 2.0.3 reference-pack IL: System.Object.BaseType is nil and the AssemblyRef table is empty.
  • Compiled a C# consumer with the SDK's csc.dll /noconfig /nostdlib /target:library, referencing only the reassembled netstandard: passed. The same consumer against the nil-base-only intermediate assembly failed with CS0518.

The original source-build pipeline was not rerun.

Note

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

@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.

@jkotas
jkotas requested a balanced review from Copilot November 3, 2026 20:29

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 were identified for the core-library type-resolution changes.

No open issues 🎉

What changed in this PR

This PR corrects core-library type resolution in managed ilasm so generated reference assemblies can be recognized by the C# compiler without unintended mscorlib dependencies.

Changes:

  • Keeps core-library System.Object baseless, including explicit and repeated declarations.
  • Resolves implicit bases, unqualified well-known types, and generated debug attributes locally in core-library mode while preserving explicit external references.
  • Adds regression coverage for root bases, local metadata handles, assembly-reference boundaries, and debug attributes.
File Description
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypeReferenceTests.cs Tests local resolution, debug attributes, and preservation of explicit external references.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypeDefinitionTests.cs Tests baseless root objects and local versus external implicit bases.
src/​tools/​ilasm/​src/​ILAssembler/​EntityRegistry.cs Centralizes core-library state and adds local type and scope resolution.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.Types.References.cs Avoids external well-known-type lookup in core-library mode.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.Types.Headers.cs Enforces the root-object rule during initial and repeated declarations.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.Manifest.Assembly.cs Records core-library detection in the entity registry.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.Declarations.Actions.cs Routes the .mscorlib directive to shared registry state.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.Conversions.cs Removes the former grammar-local core-library flag.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.BuildImage.cs Uses the appropriate core-library scope for generated debug attributes.

Review effort: Balanced

@jkoritzinsky
jkoritzinsky enabled auto-merge (squash) November 3, 2026 21:54
@jkoritzinsky
jkoritzinsky merged commit bab694f into dotnet:main Nov 4, 2026
63 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Nov 4, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 4, 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