Visitar URL original
[ObjCRuntime] Reject non-native generic arguments in exported signatures. Fixes #15709 by rolfbjarne · Pull Request #27291 · dotnet/macios · GitHub
Skip to content

[ObjCRuntime] Reject non-native generic arguments in exported signatures. Fixes #15709 - #27291

Open
rolfbjarne wants to merge 3 commits into
mainfrom
dev/rolf/nsobject-generics-documentation
Open

rolfbjarne wants to merge 3 commits into
mainfrom
dev/rolf/nsobject-generics-documentation

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Make the dynamic registrar reject exported signatures such as EnumWrapper<MyEnum> with error 4167 instead of accepting them accidentally. Check generic arguments recursively, while keeping native-object arguments, non-generic derived wrappers, and non-NSObject native wrappers supported.

Add regression coverage and update the error documentation. The full NSObject generics guide is being ported in dotnet/docs-mobile#156.

Fixes #15709

🤖 Pull request created by Copilot

rolfbjarne and others added 3 commits November 11, 2026 09:29
…res.

Validate generic native-object signatures in the shared registrar so the dynamic registrar reports error 4167 for enum and other non-native generic arguments, including nested wrappers.

Cover rejected return and parameter signatures, supported native-object arguments, and the non-generic subclass workaround. Update the diagnostic documentation to describe the restriction.

Fixes #15709.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Limit the generic argument check to NSObject subclasses, matching the static registrar. Keep other INativeObject wrappers supported and add a regression case for a generic NativeObject wrapper with a string argument.

Clarify the scope of error 4167 in its documentation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoid resolving CoreFoundation to the sibling test namespace.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 08:49

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.

🟡 Changes recommended

The shared registrar change lacks coverage for the Cecil-based static registration path, since the regression test exercises only dynamic Runtime.ConnectMethod registration.

1 open issue
What changed in this PR

This PR addresses #15709 by tightening exported-signature validation so the dynamic registrar rejects unsupported generic arguments with error 4167.

Changes:

  • Reject non-native generic arguments recursively for NSObject wrappers.
  • Add dynamic-registration tests for invalid signatures and supported wrapper forms.
  • Update error 4167 documentation with the restriction and a workaround.
File Description
tests/​monotouch-test/​ObjCRuntime/​RegistrarTest.cs Adds regression coverage for rejected and supported generic signatures.
src/​ObjCRuntime/​Registrar.cs Requires generic arguments of NSObject wrappers to implement INativeObject.
docs/​website/​mtouch-errors.md Corrects error 4167 guidance and recommends non-generic subclasses.

Review effort: Balanced

Comment on lines +2823 to +2824
if (IsNSObject (type) && !IsINativeObject (argument))
throw CreateException (4167, member, Errors.MT4167, member?.FullName, GetTypeFullName (type), GetTypeFullName (argument));
@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: dd2e1ad57fca4bee13b59bed54b9db9c8108ddf8 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #dd2e1ad] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 1 tests failed, 216 tests passed.

Failures

❌ monotouch tests (iOS)

1 tests failed, 19 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Release (compat inline dlfcn): TimedOut

Html Report (VSDrops) Download

Successes

✅ 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 1 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 (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: dd2e1ad57fca4bee13b59bed54b9db9c8108ddf8 [PR build]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error MT4166 / MM4166 (Cannot register the method...) for generic property only in Release

3 participants