[release/10.0.1xx] [src] Add a [DynamicDependency] attribute from the event field to exported method for generated events. Fixes #24262.#24288
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a trimming issue where the trimmer could remove exported methods for generated events, preventing events from being raised. The fix adds a [DynamicDependency] attribute to event backing fields that references the corresponding delegate method, ensuring the trimmer preserves these methods when events are subscribed to.
Key Changes:
- Added
[DynamicDependency(nameof(...))]attribute to generated event backing fields in the binding generator - Added comprehensive tests covering both custom types and SDK types (NSCache)
- Updated expected NativeAOT app sizes to reflect the additional preserved code
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/bgen/Generator.cs | Added [DynamicDependency] attribute to event field declarations to prevent trimmer from removing delegate methods |
| tests/bindings-test/ApiDefinition.cs | Added Hitchhiker and HitchhikerDelegate binding definitions for testing custom type events |
| tests/test-libraries/libtest.h | Added Objective-C interface declarations for Hitchhiker test class |
| tests/test-libraries/libtest.m | Added Objective-C implementation for Hitchhiker test class |
| tests/monotouch-test/ObjCRuntime/RegistrarTest.cs | Added two test methods validating event handling for custom and SDK types |
| tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt | Updated expected app bundle sizes reflecting preserved code (~20KB increase) |
| Assert.That (earthDestroyed, Is.True, "Event raised"); | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
[nitpick] Extra blank line. Consider removing this extra line to maintain consistency with the spacing between other test methods in this file.
This reverts commit da4d4c7.
✅ [CI Build #ca21234] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #ca21234] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #ca21234] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #ca21234] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #ca21234] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #ca21234] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
💻 [CI Build #ca21234] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #ca21234] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #ca21234] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 120 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Otherwise the trimmer might end up trimming away the exported method, and if that happens, the event will never be raised.
Fixes #24262.
Backport of #24270.