Skip to content

[tools] Fix IL2009 warning for generic types in linker XML descriptors - #25415

Merged
rolfbjarne merged 5 commits into
mainfrom
dev/rolf/ilc-xml-generic-methods
May 13, 2026
Merged

rolfbjarne merged 5 commits into
mainfrom
dev/rolf/ilc-xml-generic-methods

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

When a method has generic parameter types (like 'T' in Callback),
the linker XML descriptor can't resolve the generic parameter name in
the method signature. Use the method 'name' attribute instead of
'signature' for such methods, which matches by name and avoids the
IL2009 warning.

Fixes this warning, which shows up in MAUI's tests (and our own too, just not
in a place where we were validating warnings):

warning IL2009: Could not find method 'System.Void Activated(T)' on type 'UIKit.UIGestureRecognizer.Callback`1'

When a method has generic parameter types (like 'T' in Callback),
the linker XML descriptor can't resolve the generic parameter name in
the method signature. Use the method 'name' attribute instead of
'signature' for such methods, which matches by name and avoids the
IL2009 warning.

Fixes this warning, which shows up in MAUI's tests (and our own too, just not
in a place where we were validating warnings):

> warning IL2009: Could not find method 'System.Void Activated(T)' on type 'UIKit.UIGestureRecognizer.Callback`1'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 06:38

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.

Pull request overview

This PR updates the dotnet-linker’s generated XML root descriptor output to avoid IL2009 warnings when preserving methods whose signatures contain generic parameter names (for NativeAOT/ILC scenarios where such signatures can’t be resolved).

Changes:

  • Track MethodDefinition alongside the “conditional” flag for preserved methods so XML emission can choose between signature vs name.
  • Emit instead of when the method’s signature contains generic parameters, avoiding IL2009.

Comment thread tools/dotnet-linker/ApplyPreserveAttributeStep.cs Outdated
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 4 commits May 13, 2026 11:01
Add a test that builds monotouch-test with NativeAOT and verifies
no IL2009 warnings are emitted. Also assert IL2026 warnings are
still present so we're notified if they go away.

Fix HasGenericParameterInSignature to use ContainsGenericParameter
instead of checking for direct GenericParameter types, which handles
nested generic parameters (e.g. Action, T[], ref T, Nullable).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The NativeAOT monotouch-test build doesn't produce IL2026 warnings,
so remove that assertion. The IL2009 check is sufficient to verify
the fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assert the exact set of warnings for the NativeAOT monotouch-test
build using the existing AssertWarnings/ExpectedBuildMessage pattern.
This ensures we're notified if any warnings are fixed or new ones
appear. All platforms currently produce the same set of warnings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rolfbjarne
rolfbjarne enabled auto-merge (squash) May 13, 2026 11:14
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #cf3c7ab] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: cf3c7abc1e3c710c8369a8609beb6fcc9ce61db5 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #cf3c7ab] Build passed (Build packages) ✅

Pipeline on Agent
Hash: cf3c7abc1e3c710c8369a8609beb6fcc9ce61db5 [PR build]

@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: cf3c7abc1e3c710c8369a8609beb6fcc9ce61db5 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #cf3c7ab] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: cf3c7abc1e3c710c8369a8609beb6fcc9ce61db5 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #cf3c7ab] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 175 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. (⚠️ Html Report Publish failed ⚠️) 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. [attempt 2] 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 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 16 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 16 tests passed. [attempt 2] 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. [attempt 2] 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 Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ 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

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: cf3c7abc1e3c710c8369a8609beb6fcc9ce61db5 [PR build]

@rolfbjarne
rolfbjarne merged commit 672b410 into main May 13, 2026
49 checks passed
rolfbjarne added a commit that referenced this pull request May 20, 2026
…nker XML descriptors (#25477)

When a method has generic parameter types (like 'T' in Callback),
the linker XML descriptor can't resolve the generic parameter name in
the method signature. Use the method 'name' attribute instead of
'signature' for such methods, which matches by name and avoids the
IL2009 warning.

Fixes this warning, which shows up in MAUI's tests (and our own too, just not
in a place where we were validating warnings):

> warning IL2009: Could not find method 'System.Void Activated(T)' on type 'UIKit.UIGestureRecognizer.Callback`1'

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Backport of #25415.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants