Skip to content

[src] Convert manual binding factories to [FactoryMethod] - #26376

Open
rolfbjarne wants to merge 5 commits into
mainfrom
dev/rolf/factorymethod-conversions
Open

[src] Convert manual binding factories to [FactoryMethod]#26376
rolfbjarne wants to merge 5 commits into
mainfrom
dev/rolf/factorymethod-conversions

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Convert five hand-written failable-initializer factory helpers to use the new bgen [FactoryMethod] attribute (added in #26196). Each conversion replaces an [Internal] NativeHandle _InitWith... helper plus a manual partial-class factory method with a [FactoryMethod] [return: NullAllowed] NativeHandle Constructor (...) in the binding definition, letting the generator emit the public static T? Create (...) factory. The manual partial-class files are deleted and their entries removed from frameworks.sources.

🤖 Pull request created by Copilot

rolfbjarne and others added 5 commits July 31, 2026 15:31
…FactoryMethod]

Replace the hand-written SCVideoStreamAnalyzer.Create factory (a manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrapper around the failable
`initWithParticipantUUID:streamDirection:error:` initializer) with the bgen
[FactoryMethod] attribute on the binding constructor.

The generated `public static SCVideoStreamAnalyzer? Create (string
participantUuid, SCVideoStreamAnalyzerStreamDirection streamDirection, out
NSError? error)` is identical to the previous manual factory (same name,
signature, nullable return, nil-check/dispose behavior), verified against the
generated source and compiled into Microsoft.iOS.dll. The manual partial-class
file is deleted and its frameworks.sources entry removed. This binding has
monotouch-test coverage (SCVideoStreamAnalyzerTest).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
Replace the hand-written AVCaptureEventSound.Create factory (a manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrapper around the failable
`initWithURL:error:` initializer) with the bgen [FactoryMethod] attribute on
the binding constructor.

The generated `public static AVCaptureEventSound? Create (NSUrl url, out
NSError? error)` is identical to the previous manual factory (same name,
signature, nullable return, nil-check/dispose behavior), verified against the
generated source and compiled into Microsoft.iOS.dll. The manual partial-class
file is deleted and its frameworks.sources entry removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
…[FactoryMethod]

Replace the hand-written AVSpeechSynthesisProviderAudioUnit.Create factory (a
manual `new (NSObjectFlag.Empty)` + InitializeHandle wrapper around the failable
`initWithComponentDescription:options:error:` initializer) with the bgen
[FactoryMethod] attribute on the binding constructor.

The generated `public static AVSpeechSynthesisProviderAudioUnit? Create
(AudioComponentDescription componentDescription, AudioComponentInstantiationOptions
options, out NSError? error)` is identical to the previous manual factory (same
name, signature, nullable return, nil-check/dispose behavior). The binding init
parameter was renamed outError -> error to preserve the public parameter name.
Verified against the generated source and compiled into Microsoft.iOS.dll. The
manual partial-class file is deleted and its frameworks.sources entry removed.
This binding has monotouch-test coverage (AVSpeechSynthesisProviderAudioUnitTest).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
…ethod]

Replace the two hand-written BAAssetPackManifest.Create factories (manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrappers around the failable
`initWithContentsOfURL:applicationGroupIdentifier:error:` and
`initFromData:applicationGroupIdentifier:error:` initializers) with the bgen
[FactoryMethod] attribute on two binding constructors.

The generated `public static BAAssetPackManifest? Create (NSUrl url, string
applicationGroupIdentifier, out NSError? error)` and `Create (NSData data,
string applicationGroupIdentifier, out NSError? error)` overloads are identical
to the previous manual factories (same names, signatures, nullable return,
nil-check/dispose behavior), verified against the generated source and compiled
into Microsoft.iOS.dll. The manual partial-class file is deleted and its
frameworks.sources entry removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
Replace the two hand-written WKWebExtensionMatchPattern.Create factories (manual
`new (NSObjectFlag.Empty)` + InitializeHandle wrappers around the failable
`initWithString:error:` and `initWithScheme:host:path:error:` initializers) with
the bgen [FactoryMethod] attribute on two binding constructors.

The generated `public static WKWebExtensionMatchPattern? Create (string @string,
out NSError? error)` and `Create (string scheme, string host, string path, out
NSError? error)` overloads are identical to the previous manual factories (same
names, signatures, nullable return, nil-check/dispose behavior), and coexist
with the existing `[Static]` `Create` overloads (matchPatternWithString: /
matchPatternWithScheme:host:path:) that take no error argument. Verified against
the generated source and compiled into Microsoft.iOS.dll. The manual
partial-class file is deleted and its frameworks.sources entry removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad44b4bd-764c-4d93-811a-fd5a1f6237e6
Copilot AI review requested due to automatic review settings July 31, 2026 13:33
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner July 31, 2026 13:33

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 migrates five hand-written “failable initializer” factory implementations to bgen’s new [FactoryMethod] support, so the generator emits nullable Create(...) factories automatically and the redundant manual partial-class helpers can be removed.

Changes:

  • Replaced [Internal] NativeHandle _InitWith... init helpers with [FactoryMethod] failable constructor bindings ([return: NullAllowed] NativeHandle Constructor (...)) for five types.
  • Deleted the corresponding hand-written partial-class Create(...) implementations.
  • Removed the deleted source files from src/frameworks.sources.

Reviewed changes

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

Show a summary per file
File Description
src/WebKit/WKWebExtensionMatchPattern.cs Deletes the manual Create(...) factory helpers for failable initializers.
src/webkit.cs Adds [FactoryMethod] constructor bindings for WKWebExtensionMatchPattern failable initializers.
src/SensitiveContentAnalysis/SCVideoStreamAnalyzer.cs Deletes the manual Create(...) factory helper.
src/sensitivecontentanalysis.cs Adds a [FactoryMethod] constructor binding for the failable initializer.
src/BackgroundAssets/BAAssetPackManifest.cs Deletes the manual Create(...) factory helpers.
src/backgroundassets.cs Adds [FactoryMethod] constructor bindings for the two failable initializers.
src/AVKit/AVCaptureEventSound.cs Deletes the manual Create(...) factory helper.
src/avkit.cs Adds a [FactoryMethod] constructor binding for the failable initializer.
src/AVFoundation/AVSpeechSynthesisProviderAudioUnit.cs Deletes the manual Create(...) factory helper.
src/avfoundation.cs Adds a [FactoryMethod] constructor binding for the failable initializer.
src/frameworks.sources Removes the deleted partial-class source files from the build inputs.

Comment thread src/backgroundassets.cs
Comment on lines +411 to +414
[FactoryMethod]
[Export ("initWithContentsOfURL:applicationGroupIdentifier:error:")]
NativeHandle _InitWithContentsOfUrl (NSUrl url, string applicationGroupIdentifier, [NullAllowed] out NSError error);

[Internal]
[return: NullAllowed]
NativeHandle Constructor (NSUrl url, string applicationGroupIdentifier, [NullAllowed] out NSError error);
@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: 4f9a40837b5f876f59ff2935b647a1819d86c0be [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #4f9a408] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 46 tests failed, 157 tests passed.

Failures

❌ cecil tests

1 tests failed, 0 tests passed.

Failed tests

  • Cecil-based tests: Failed (Execution failed with exit code 1)
    • Cecil.Tests.ConstructorTest.NoConstructorsWithOutErrorArguments: Multiple failures or warnings in test:
  1. SensitiveContentAnalysis.SCVideoStreamAnalyzer::.ctor(System.String,SensitiveContent...

Html Report (VSDrops) Download

❌ dotnettests tests (iOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppIconTest.AlternateAppIcon_Failure(iOS,"ios-arm6...: Failure when comparing error messages:
      Unexpected error message #0:
      Expected: Can't find the AlternateAppIcon 'InexistentAppI...
    • Xamarin.Tests.AppIconTest.AlternateAppIcon(iOS,"ios-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • Xamarin.Tests.AppIconTest.AlternateAppIcons(iOS,"ios-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • ... and 61 more

Html Report (VSDrops) Download

❌ dotnettests tests (macOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.ExtensionsTest.AdditionalAppExtensionTest(MacOSX,"...: 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...

Html Report (VSDrops) Download

❌ dotnettests tests (tvOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppIconTest.AlternateAppIcon_Failure(TVOS,"tvos-ar...: Failure when comparing error messages:
      Unexpected error message #0:
      Expected: Can't find the AlternateAppIcon 'InexistentAppI...
    • Xamarin.Tests.AppIconTest.AlternateAppIcon(TVOS,"tvos-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • Xamarin.Tests.AppIconTest.AlternateAppIcons(TVOS,"tvos-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • ... and 31 more

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

19 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Debug: BuildFailure
  • monotouch-test/iOS - simulator/Release (link sdk): BuildFailure
  • monotouch-test/iOS - simulator/Release (link all): BuildFailure
  • monotouch-test/iOS - simulator/Debug (PrepareAssemblies): BuildFailure
  • monotouch-test/iOS - simulator/Debug (PrepareAssemblies, inline dlfcn, dont link): BuildFailure
  • monotouch-test/iOS - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/iOS - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/iOS - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/iOS - simulator/Release (NativeAOT): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, NativeAOT): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS - simulator/Debug (managed static registrar): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS - simulator/Release (managed static registrar, all optimizations): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS - simulator/Debug (interpreter): BuildFailure
  • monotouch-test/iOS - simulator/Release (interpreter): BuildFailure
  • monotouch-test/iOS - simulator/Release (compat inline Class.GetHandle): BuildFailure
  • monotouch-test/iOS - simulator/Release (strict inline Class.GetHandle): BuildFailure
  • monotouch-test/iOS - simulator/Release (compat inline dlfcn): BuildFailure
  • monotouch-test/iOS - simulator/Release (strict inline dlfcn, link sdk): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS - simulator/Release (NativeAOT, .NET 11 defaults): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

19 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug: BuildFailure
  • monotouch-test/tvOS - simulator/Release (link sdk): BuildFailure
  • monotouch-test/tvOS - simulator/Release (link all): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (PrepareAssemblies): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (PrepareAssemblies, inline dlfcn, dont link): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (static registrar): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (all optimizations): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (NativeAOT): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (trimmable static registrar, NativeAOT): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Debug (managed static registrar): BuildFailure
  • monotouch-test/tvOS - simulator/Release (managed static registrar, all optimizations): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (interpreter): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (interpreter): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (compat inline Class.GetHandle): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (strict inline Class.GetHandle): BuildFailure
  • monotouch-test/tvOS - simulator/Release (compat inline dlfcn): BuildFailure
  • monotouch-test/tvOS - simulator/Release (strict inline dlfcn, link sdk): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (NativeAOT, .NET 11 defaults): BuildFailure

Html Report (VSDrops) Download

❌ msbuild tests

1 tests failed, 1 tests passed.

Failed tests

  • MSBuild tasks tests: Failed (Execution failed with exit code 1)
    • Xamarin.MacDev.Tasks.DetectSigningIdentityTaskTests.CustomEntitl...: #RunTask-ErrorCount
      : error: No valid iOS code signing keys found in keychain. You need to request a codesigning certificate ...
    • Xamarin.MacDev.Tasks.DetectSigningIdentityTaskTests.EmptyEntitle...: #RunTask-ErrorCount
      : error: No valid iOS code signing keys found in keychain. You need to request a codesigning certificate ...
    • Xamarin.MacDev.Tasks.DetectSigningIdentityTaskTests.EmptyEntitle...: #RunTask-ErrorCount
      : error: No valid iOS code signing keys found in keychain. You need to request a codesigning certificate ...
    • ... and 7 more

Html Report (VSDrops) Download

❌ windows tests

1 tests failed, 2 tests passed.

Failed tests

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.AppWithLibraryWithResourcesReferenceOnRemoteWindows(iOS,"ios-arm64",True): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.PluralRuntimeIdentifiersWithRemoteMac(iOS,"ios-arm64","Release"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.AppWithLibraryWithResourcesReferenceOnRemoteWindows(iOS,"ios-arm64",False): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.BundleStructureWithRemoteMac(iOS,"ios-arm64",All,"Debug"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.PostBuildTest.BuildIpaAndArchiveOnRemoteWindowsTest(iOS,"ios-arm64"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.PluralRuntimeIdentifiersWithRemoteMac(iOS,"ios-arm64","Debug"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.StripTest(iOS,"ios-arm64","Release"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.BuildProjectsWithExtensionsOnRemoteWindows(iOS,"ios-arm64",False): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.AssemblyPreparerRemoteTest(iOS,"ios-arm64"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.RemoteTest(iOS,"ios-arm64"): Failed: 'dotnet build' failed with exit code 1

Html Report (VSDrops) Download

❌ xtro tests

1 tests failed, 0 tests passed.

Failed tests

  • Xtro: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.Xtro.RunTest: ExitCode
      Assert.That(rv, Is.EqualTo (0))
      Expected: 0
      But was: 2

Html Report (VSDrops) Download

❌ Tests on macOS Tahoe (26) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 monotouch-test: Failed (exit code 132)
    • No test failure details available. Output tail:
      • Xamarin.Mac.Tests.AppleScriptTests
      • [PASS] AppleScript_BasicTest
      • Xamarin.Mac.Tests.AppleScriptTests : 75.845 ms
      • Xamarin.Mac.Tests.AudioUnitTests
      • [PASS] AudioObjectPropertyScope4CCTest
      • [PASS] AudioObjectPropertySelector4CCTest
      • [PASS] GetCurrentDevice_Test
      • Xamarin.Mac.Tests.AudioUnitTests : 5.0938 ms
      • Xamarin.Mac.Tests.AUGraphTests
      • Execution completed with exit code 132

Html Report (VSDrops) Download

Successes

✅ assembly-processing: 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
✅ 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 (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 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

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 4f9a40837b5f876f59ff2935b647a1819d86c0be [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/873a416a6eb17ff6cf498534c4d27c13
Updated files
  • TVOS-MonoVM-interpreter-preservedapis.txt
  • TVOS-MonoVM-preservedapis.txt

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

3 participants