Skip to content

[bgen] Support Wrap on protocol members. Fixes #9696 - #27180

Open
rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/protocol-wrap-candidates
Open

rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/protocol-wrap-candidates

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Generate default interface implementations for wrapped protocol methods and properties, including accessor-level conversions. Keep these managed conveniences separate from exported protocol members so they do not add Objective-C selectors or required/optional protocol metadata. Wrapped methods on model classes now execute their forwarding bodies instead of throwing.

Expose the existing typed delegates, dictionaries, enum arrays, struct conversions and compatibility aliases through protocol interfaces. Move the handwritten CISystemToneMap dynamic-range properties into the binding definition, preserving the concrete class API through filter generation.

Add cross-platform regression coverage for wrappers, inheritance, model classes, static members and the ported APIs. Document the newly visible members and remove the documentation failures resolved by those comments.

Fixes #9696

🤖 Pull request created by Copilot

Generate default interface implementations for wrapped protocol methods and properties, including accessor-level conversions. Keep these managed conveniences separate from exported protocol members so they do not add Objective-C selectors or required/optional protocol metadata. Wrapped methods on model classes now execute their forwarding bodies instead of throwing.

Expose the existing typed delegates, dictionaries, enum arrays, struct conversions and compatibility aliases through protocol interfaces. Move the handwritten CISystemToneMap dynamic-range properties into the binding definition, preserving the concrete class API through filter generation.

Add cross-platform regression coverage for wrappers, inheritance, model classes, static members and the ported APIs. Document the newly visible members and remove the documentation failures resolved by those comments.

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

Copilot-Session: c4e0d085-6d69-4fcb-8232-75056e83a58f
Replace the null-forgiving conversion in the newly exposed protocol overload with an explicit ArgumentOutOfRangeException when the enum has no native constant. This avoids hiding a nullable conversion and gives callers an actionable error before invoking the underlying binding. Document the exception on the shared binding definition.

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

Copilot-Session: c4e0d085-6d69-4fcb-8232-75056e83a58f
Copilot AI balanced review requested due to automatic review settings October 29, 2026 20:53
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner October 29, 2026 20:53

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

Cross-assembly protocol inheritance can fail binding generation with BI1018 because non-exported convenience properties are imported as contracts, and regression tests leave generated setters unchecked.

2 open issues
What changed in this PR

Adds [Wrap] support to bgen protocol interfaces, addressing #9696 by exposing managed convenience members without adding Objective-C protocol metadata.

Changes:

  • Generates default interface implementations for wrapped methods, properties, and accessors, and forwarding bodies for model methods.
  • Moves CISystemToneMap.PreferredDynamicRange into the binding definition while preserving its concrete-class API.
  • Adds cross-platform regression coverage, documents exposed APIs, and removes resolved documentation failures.
File Description
tests/​cecil-tests/​Documentation.KnownFailures.txt Removes entries for newly documented APIs.
tests/​bgen/​tests/​protocol-wrap.cs Adds protocol wrapper binding fixtures.
tests/​bgen/​ProtocolWrapTests.cs Checks generated wrappers and platform APIs.
src/​videotoolbox.cs Documents pixel format and buffer wrappers.
src/​uikit.cs Documents the typed preview delegate.
src/​photosui.cs Documents the category overload and rejects invalid constants.
src/​mediaextension.cs Documents sample information wrappers.
src/​frameworks.sources Removes handwritten tone-map source entries.
src/​CoreImage/​ICISystemToneMapProtocol.cs Removes the handwritten interface property.
src/​CoreImage/​CISystemToneMap.cs Removes the handwritten class property.
src/​coreimage.cs Defines the tone-map property using accessor wrappers.
src/​browserenginekit.cs Documents the asynchronous input delegate.
src/​bgen/​Generator.cs Emits managed protocol wrappers and model forwarding bodies.
src/​bgen/​Filters.cs Generates wrapped properties on concrete filters.
src/​avfoundation.cs Documents the download callback alias.
src/​authenticationservices.cs Documents algorithm-array wrappers.
src/​appkit.cs Documents the item-count compatibility alias.
docs/​website/​binding_types_reference_guide.md Explains protocol wrapper behavior.

Review effort: Balanced

Comment thread src/bgen/Generator.cs
Comment on lines +5277 to +5278
foreach (var pi in SelectProtocolProperties (type, wrapped: true)) {
GenerateProperty (type, pi, null, false, is_protocol_member: true);
Assert.That (type, Is.Not.Null, member.Type);
var property = type.Properties.FirstOrDefault (v => v.Name == member.Member);
if (property is not null) {
Assert.That (property.GetMethod?.HasBody, Is.True, property.FullName);
@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: de9507ae3ae49d4e3da2b40295fb48e5ffddea18 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #de9507a] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 5 tests failed, 212 tests passed.

Failures

❌ dotnettests tests (macOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppSizeTest.CoreCLR_R2R(MacOSX,"osx-arm64;osx-x64"...: App size changed significantly (+11,411 bytes (11.1 KB = 0.0 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB)). Ex...

Html Report (VSDrops) Download

❌ generator tests

1 tests failed, 0 tests passed.

Failed tests

  • BGen tests: Failed (Execution failed with exit code 1)
    • GeneratorTests.BGenTests.StackOverflow20696157: BGen failed with exit code 1: build
      Microsoft (R) Visual C# Compiler version 5.13.0-1.26523.103 (846769e14f918f16ee85e7055c72fcc...

Html Report (VSDrops) Download

❌ windows tests

1 tests failed, 2 tests passed.

Failed tests

  • BGen tests/GeneratorTests.ProtocolWrapTests.PlatformMembers(macOSMobile): Failed: System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\AzDO_work\7\s\macios\tests\dotnet\Windows\bin\dotnet\packs\MACOS_NUGET_RUNTIME_MANAGED_NAME not found\27.0.13381-ci.pr.gh27180\runtimes\osx\lib\net12.0\Microsoft.macOS.dll'.

  • BGen tests/GeneratorTests.ProtocolWrapTests.PlatformMembers(MacCatalyst): Failed: System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\AzDO_work\7\s\macios\tests\dotnet\Windows\bin\dotnet\packs\MACCATALYST_NUGET_RUNTIME_MANAGED_NAME not found\27.0.13381-ci.pr.gh27180\runtimes\maccatalyst\lib\net12.0\Microsoft.MacCatalyst.dll'.

  • BGen tests/GeneratorTests.ProtocolWrapTests.PlatformMembers(tvOS): Failed: System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\AzDO_work\7\s\macios\tests\dotnet\Windows\bin\dotnet\packs\TVOS_NUGET_RUNTIME_MANAGED_NAME not found\27.0.13381-ci.pr.gh27180\runtimes\tvos\lib\net12.0\Microsoft.tvOS.dll'.

  • BGen tests/GeneratorTests.ProtocolWrapTests.PlatformMembers(iOS): Failed: System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\AzDO_work\7\s\macios\tests\dotnet\Windows\bin\dotnet\packs\IOS_NUGET_RUNTIME_MANAGED_NAME not found\27.1.12086-ci.pr.gh27180\runtimes\ios\lib\net12.0\Microsoft.iOS.dll'.

  • BGen tests/GeneratorTests.BGenTests.StackOverflow20696157: Failed: BGen failed with exit code 1: build

Html Report (VSDrops) Download

❌ Tests on macOS Sonoma (14) tests

1 tests failed, 4 tests passed.

Failed tests

  • MacCatalyst/maccatalyst-x64 monotouch-test: Failed (exit code 1)
    • [FAIL] PerformAsynchronousFileAccess_Null : System.UnauthorizedAccessException : Access to the path '/Users/builder/Documents/mydocument.txt' is denied.
    • [FAIL] Save : System.UnauthorizedAccessException : Access to the path '/Users/builder/Documents/mydocument.txt' is denied.

Html Report (VSDrops) Download

❌ Tests on macOS Sequoia (15) tests

1 tests failed, 4 tests passed.

Failed tests

  • MacCatalyst/maccatalyst-x64 monotouch-test: Failed (exit code 137)
    • No test failure details available. Output tail:
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run(NUnit.Framework.Internal.Test)
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run()
      • at MonoTouch.NUnit.UI.BaseTouchRunner.<AutoRun>b__49_0()
      • at MonoTouch.NUnit.UI.TouchRunner+<>c__DisplayClass19_0.<ExecuteOnMainThread>b__0()
      • at Foundation.NSAsyncActionDispatcher.Apply()
      • at __Registrar_Callbacks__.callback_3037_Foundation_NSAsyncActionDispatcher_Apply(IntPtr, IntPtr, IntPtr*)
      • at UIKit.UIApplication.UIApplicationMain(Int32, System.String[], IntPtr, IntPtr)
      • at UIKit.UIApplication.Main(System.String[], System.Type, System.Type)
      • at MainClass.Main(System.String[])
      • Execution completed with exit code 137
  • MacCatalyst/maccatalyst-arm64 monotouch-test: Failed (exit code 137)
    • No test failure details available. Output tail:
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run(NUnit.Framework.Internal.Test)
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run()
      • at MonoTouch.NUnit.UI.BaseTouchRunner.<AutoRun>b__49_0()
      • at MonoTouch.NUnit.UI.TouchRunner+<>c__DisplayClass19_0.<ExecuteOnMainThread>b__0()
      • at Foundation.NSAsyncActionDispatcher.Apply()
      • at __Registrar_Callbacks__.callback_3037_Foundation_NSAsyncActionDispatcher_Apply(IntPtr, IntPtr, IntPtr*)
      • at UIKit.UIApplication.UIApplicationMain(Int32, System.String[], IntPtr, IntPtr)
      • at UIKit.UIApplication.Main(System.String[], System.Type, System.Type)
      • at MainClass.Main(System.String[])
      • Execution completed with exit code 137

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 (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
✅ 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. 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
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ 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: de9507ae3ae49d4e3da2b40295fb48e5ffddea18 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

⚠️ AppSizeTest expected files changed ⚠️

The AppSizeTest detected changes in the expected app size files.

To update the expected files, add a comment with the following command:

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/766e3274cc44ebb480571ea0a73fd399
Updated files
  • MacOSX-CoreCLR-R2R-size.txt

Pipeline on Agent
Hash: de9507ae3ae49d4e3da2b40295fb48e5ffddea18 [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.

[Generator] Add support for Wrap on protocols

3 participants