Skip to content

Fix NativeAOT namespace lookup for nested generic types - #135177

Merged
jkotas merged 13 commits into
mainfrom
copilot/nativeaot-fix-null-namespace
Oct 5, 2026
Merged

jkotas merged 13 commits into
mainfrom
copilot/nativeaot-fix-null-namespace

Conversation

Copilot AI commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

NativeAOT returned null for Type.Namespace on nested generic types, despite their namespace-qualified FullName.

  • Metadata: Stop emitting namespace definitions for nested types and document the schema invariant.
  • Reflection: Resolve namespaces through enclosing types; exclude nested types from top-level well-known attribute matching.
  • Coverage: Add cases for nested generic definitions and constructions, global-namespace nesting, and nested attribute lookalikes.

Fixes #135106

@azure-pipelines

azure-pipelines Bot commented Oct 4, 2026 •

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

Copilot AI and others added 2 commits October 4, 2026 02:05
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix null Type.Namespace for nested generic types in NativeAOT Fix NativeAOT namespace lookup for nested generic types Oct 4, 2026
Copilot AI requested a review from jkotas October 4, 2026 02:32
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

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.

Copilot review overview

🔵 Needs a closer look

The approach appears consistent, but changing NativeAOT’s metadata schema and every major consumer has a broad binary-format blast radius requiring maintainer review.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes NativeAOT namespace resolution for nested types by encoding their structural parent and traversing enclosing types during reflection.

Changes:

  • Unifies namespace/enclosing-type metadata.
  • Updates all NativeFormat consumers.
  • Adds nested generic, global namespace, and attribute-lookalike tests.
File Description
TypeInfoTests.cs Adds regression coverage.
NativeFormatReaderGen.cs Reads the unified parent handle.
MetadataTypeHashingAlgorithms.cs Hashes types by structural parent.
SchemaDef.cs Defines the new schema invariant.
NativeMetadataWriter.cs Formats unified parent records.
NativeFormatWriterGen.cs Writes the unified parent handle.
Transform.Type.cs Emits namespace or enclosing type.
MetadataNameExtensions.cs Traverses structural parents.
StackTraceMetadata.cs Resolves assembly through parents.
MethodNameFormatter.cs Formats nested type names.
NativeFormatRuntimeNamedTypeInfo.cs Resolves inherited namespaces.
TypeResolver.NativeFormat.cs Uses the renamed parent handle.
MetadataReaderExtensions.NativeFormat.cs Excludes nested attribute lookalikes.

Comment thread src/coreclr/tools/Common/Internal/Metadata/NativeFormat/Generator/SchemaDef.cs Outdated
Comment thread src/coreclr/tools/Common/Internal/Metadata/NativeFormat/Generator/SchemaDef.cs Outdated
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
@jkotas

jkotas commented Oct 4, 2026

Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@jkotas

jkotas commented Oct 5, 2026

Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@jkotas

jkotas commented Oct 5, 2026

Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@jkotas

jkotas commented Oct 5, 2026

Copy link
Copy Markdown
Member

/ba-g known issue #135096

@jkotas
jkotas merged commit c31313e into main Oct 5, 2026
155 of 159 checks passed
@jkotas
jkotas deleted the copilot/nativeaot-fix-null-namespace branch October 5, 2026 06:18
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NativeAOT returns null Type.Namespace for a nested generic type whose FullName includes a namespace

4 participants