Skip to content

[bgen] Fix invalid code generation for delegate parameters without [BlockCallback]/[CCallback]. Fixes #10015. - #26495

Open
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/issue-10015-binding-projects-fails-to-generate-valid-f4a820
Open

[bgen] Fix invalid code generation for delegate parameters without [BlockCallback]/[CCallback]. Fixes #10015.#26495
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/issue-10015-binding-projects-fails-to-generate-valid-f4a820

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

MakeTrampoline formatted the parameter's Type object directly into the generated invocation code, relying on Type.ToString(). For generic delegate types (e.g. Action<Action<bool>>), this produces CLR-style names such as System.Action + backtick + 1[System.Boolean], which is not valid C# and causes CS1056/CS1003/etc build errors when bgen generates the trampoline code.

Use TypeManager.RenderType to correctly format the type as valid C# (e.g. global::System.Action<bool>).

Fixes #10015.

…lockCallback]/[CCallback]

MakeTrampoline formatted the parameter's Type object directly into the
generated invocation code, relying on Type.ToString(). For generic
delegate types (e.g. Action<Action<bool>>), this produces CLR-style
names such as System.Action + backtick + 1[System.Boolean], which is not valid
C# and causes CS1056/CS1003/etc build errors when bgen generates the
trampoline code.

Use TypeManager.RenderType to correctly format the type as valid C#
(e.g. global::System.Action<bool>).

Fixes #10015

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 28, 2026 15:21
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner August 28, 2026 15:21

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

Fixes an invalid bgen trampoline codegen case where a delegate parameter type was emitted using Type.ToString() (producing CLR-style generic names like System.Action\1[System.Boolean]), by rendering delegate types with TypeManager.RenderType` so generated C# is always syntactically valid.

Changes:

  • Update trampoline invocation generation to use TypeManager.RenderType for delegate-typed parameters.
  • Add a regression binding definition reproducing the Action<Action<bool>> scenario.
  • Add an ErrorTests regression test that builds the temporary binding to ensure codegen succeeds.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/bgen/Generator.cs Fixes trampoline code emission by rendering delegate types as valid C# syntax.
tests/bgen/tests/issue10015.cs Adds a minimal binding definition that triggers the problematic nested generic delegate scenario.
tests/bgen/ErrorTests.cs Adds a regression test to ensure bgen can build bindings containing the nested generic delegate type.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/bgen/ErrorTests.cs
Comment on lines +236 to +238
[Test]
[TestCase (Profile.iOS)]
public void Issue10015 (Profile profile)
@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: 80665009599b3310daf2a695de97f3c9c28c8155 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #8066500] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

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

Failures

❌ Tests on macOS Ventura (13) tests

🔥 Failed catastrophically on VSTS: test results - mac_ventura (no summary found).

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 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 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 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 Monterey (12): 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: 80665009599b3310daf2a695de97f3c9c28c8155 [PR build]

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.

Binding projects fails to generate valid code with Action<Action<bool> type

3 participants