Skip to content

[registrar] Detect open generic proxy types correctly - #26810

Merged
rolfbjarne merged 1 commit into
mainfrom
dev/rolf/ns-layout-anchor-nativeaot-warning
Oct 3, 2026
Merged

rolfbjarne merged 1 commit into
mainfrom
dev/rolf/ns-layout-anchor-nativeaot-warning

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Cecil's TypeDefinition.ContainsGenericParameter is false for open generic type definitions, so the trimmable registrar still emitted invalid newobj instructions for generic NSObject proxies. NativeAOT then reported that NSLayoutAnchor<T>_Proxy.CreateObject would always throw:

UIKit.NSLayoutAnchor_Proxy.CreateObject(native int) will always throw

Use HasGenericParameters for NSObject, INativeObject, and protocol-wrapper proxy generation, and add focused assembly-preparer coverage that verifies generic CreateObject proxies throw instead of constructing an open generic type.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
Copilot-Session: ece6a6bd-3e29-4559-b8f3-4465690e25a4

Cecil's TypeDefinition.ContainsGenericParameter is false for open generic type definitions, so the trimmable registrar still emitted invalid newobj instructions for generic NSObject proxies. NativeAOT then reported that NSLayoutAnchor<T>_Proxy.CreateObject would always throw.\n\nUse HasGenericParameters for NSObject, INativeObject, and protocol-wrapper proxy generation, and add focused assembly-preparer coverage that verifies generic CreateObject proxies throw instead of constructing an open generic type.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: ece6a6bd-3e29-4559-b8f3-4465690e25a4
Copilot AI balanced review requested due to automatic review settings October 2, 2026 13:28
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner October 2, 2026 13:28
@rolfbjarne rolfbjarne added backport-to-net11.0 Add this to issues or pull requests that should be backported to .NET 11 copilot labels Oct 2, 2026

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

🟡 Changes recommended

The generic INativeObject and protocol-wrapper proxy paths lack focused regression coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Corrects generic proxy detection in the trimmable registrar to avoid invalid open-generic construction.

Changes:

  • Uses HasGenericParameters across three proxy-generation paths.
  • Adds regression coverage for generic NSObject proxies.
File Description
tools/​dotnet-linker/​Steps/​TrimmableRegistrarStep.cs Corrects open-generic proxy detection.
tests/​assembly-preparer/​ManagedRegistrarStepTests.cs Tests generic NSObject proxy IL generation.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 90538c6295c9cf65b91643713d89230b8dad2f7f [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne enabled auto-merge (squash) October 2, 2026 18:12
@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Oct 2, 2026
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #90538c6] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 221 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 21 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 90538c6295c9cf65b91643713d89230b8dad2f7f [PR build]

@rolfbjarne
rolfbjarne merged commit 47cd74f into main Oct 3, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/ns-layout-anchor-nativeaot-warning branch October 3, 2026 12:24
dalexsoto added a commit that referenced this pull request Oct 5, 2026
…tly (#26834)

Cecil's `TypeDefinition.ContainsGenericParameter` is false for open
generic type definitions, so the trimmable registrar still emitted
invalid `newobj` instructions for generic `NSObject` proxies. NativeAOT
then reported that `NSLayoutAnchor<T>_Proxy.CreateObject` would always
throw:

```
UIKit.NSLayoutAnchor<T>_Proxy.CreateObject(native int) will always throw
```

Use `HasGenericParameters` for `NSObject`, `INativeObject`, and
protocol-wrapper proxy generation, and add focused assembly-preparer
coverage that verifies generic `CreateObject` proxies throw instead of
constructing an open generic type.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ece6a6bd-3e29-4559-b8f3-4465690e25a4

Backport of #26810.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alex Soto <alex@soto.dev>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: dalexsoto <204671+dalexsoto@users.noreply.github.com>
Copilot-Session: 02e333bf-a325-4045-a5b4-75917e002856
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-net11.0 Add this to issues or pull requests that should be backported to .NET 11 copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants