Skip to content

[AVFoundation] Fix signature for LoadTrack*/LoadTracks* methods. Fixes #25606#25653

Draft
rolfbjarne wants to merge 10 commits into
mainfrom
dev/rolf/issue-25606-loadtracks
Draft

[AVFoundation] Fix signature for LoadTrack*/LoadTracks* methods. Fixes #25606#25653
rolfbjarne wants to merge 10 commits into
mainfrom
dev/rolf/issue-25606-loadtracks

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

The completion handler callbacks for LoadTrack*/LoadTracks* methods on several AVFoundation classes had incorrect parameter types (e.g. AVMutableCompositionTrack instead of AVMovieTrack).

This PR:

  • Obsoletes the incorrectly-typed methods (guarded behind XAMCORE_5_0)
  • Adds new correctly-typed overloads with named delegate types for each class
  • Uses 2 suffix where naming conflicts arise due to delegate type inheritance relationships (AVAsset, AVMutableMovie)
  • Adds unit tests for all new APIs

Affected classes:

  • AVAsset: LoadTrack2, LoadTrackWithMediaCharacteristics, LoadTracksWithMediaType
  • AVMovie (category): LoadTrack, LoadTracksWithMediaType, LoadTracksWithMediaCharacteristic
  • AVMutableMovie: LoadTrack2, LoadTracksWithMediaType, LoadTracksWithMediaCharacteristic
  • AVFragmentedMovie (category): LoadTrack, LoadTracksWithMediaType, LoadTracksWithMediaCharacteristic
  • AVComposition (category): LoadTrack, LoadTracksWithMediaType, LoadTracksWithMediaCharacteristic

Fixes #25606

🤖 Pull request created by Copilot

rolfbjarne and others added 2 commits June 5, 2026 16:42
…ixes #25606.

Fix the completion handler parameter types for LoadTrack/LoadTracksWithMediaType/
LoadTracksWithMediaCharacteristic methods in:
- AVAsset (AVCompositionTrack -> AVAssetTrack)
- AVMutableMovie (AVMovieTrack -> AVMutableMovieTrack)
- AVFragmentedMovie (AVMutableCompositionTrack -> AVFragmentedMovieTrack)
- AVComposition (AVMutableCompositionTrack -> AVCompositionTrack)

Fixes #25606.

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

Tests cover the new correctly-typed callback overloads for:
- AVAsset.LoadTrack2, LoadTrackWithMediaCharacteristics, LoadTracksWithMediaType
- AVMovie.LoadTrack, LoadTracksWithMediaType, LoadTracksWithMediaCharacteristic
- AVMutableMovie.LoadTrack2, LoadTracksWithMediaType, LoadTracksWithMediaCharacteristic
- AVComposition.LoadTrack, LoadTracksWithMediaType, LoadTracksWithMediaCharacteristic

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

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@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.

@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 was marked as outdated.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Move #if !__TVOS__ outside the #region directives so they nest properly.

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

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@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.

…validation.

Add the attribute to the known-and-skipped list in the method attribute
validation loop, fixing BI1007 'Unknown attribute' errors during
binding generation.

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

@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.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne requested a review from Copilot June 25, 2026 11:31
@rolfbjarne

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

.NET for Apple Platforms PR Reviewer completed successfully!

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

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

Pipeline on Agent
Hash: 1f90e6ae9f3ecc9f821b74ae930efdaa16172871 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@github-actions github-actions Bot 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.

@copilot ## Review Summary

Reviewed the AVFoundation binding fixes for LoadTrack*/LoadTracks* method signatures. The approach is sound — obsoleting incorrectly-typed methods behind XAMCORE_5_0 guards and adding properly-typed replacements with named delegate types. The use of [OverloadResolutionPriority (-1)] on obsolete methods is appropriate to guide callers to the new overloads.

Issues Found:

  • ❌ 1 critical error: Copy-paste mistake in an Obsolete message (line 12853)
  • ⚠️ 1 consistency issue: Missing [Async] attribute on AVAsset wrapper (line 5734)

Positive observations:

  • Correct use of XAMCORE_5_0 guards for breaking changes
  • Named delegate types improve API clarity over generic Action<> delegates
  • Comprehensive test coverage for all new APIs
  • bgen changes properly handle OverloadResolutionPriorityAttribute
  • Platform attributes are preserved correctly

Once the two issues are addressed, this will be ready to merge.

Generated by .NET for Apple Platforms PR Reviewer for issue #25653 · 62.4 AIC · ⌖ 8.8 AIC · ⊞ 5.1K
Comment /review to run again

Comment thread src/avfoundation.cs
[Export ("loadTracksWithMediaType:completionHandler:")]
void LoadTracksWithMediaType (string mediaType, AVAssetLoadTracksCallback completionHandler);

[Wrap ("LoadTracksWithMediaType (mediaType.GetConstant ()!, completionHandler)")]

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.

🤖 ⚠️ Binding definition — Missing [Async] attribute on this [Wrap] method. All the other classes (AVMovie, AVMutableMovie, AVFragmentedMovie, AVComposition) have [Async] on their corresponding LoadTracksWithMediaType (AVMediaTypes, ...) wrap methods (lines 12744, 12871, 13156, 13793), but AVAsset is missing it here.

For consistency and to generate the async variant, add:

[Async]
[Wrap ("LoadTracksWithMediaType (mediaType.GetConstant ()!, completionHandler)")]
void LoadTracksWithMediaType (AVMediaTypes mediaType, AVAssetLoadTracksCallback completionHandler);

Rule: Consistency — follow the same pattern within the PR

Comment thread src/avfoundation.cs
#endif

#if !XAMCORE_5_0
[Obsolete ("Call the 'LoadTracksWithMediaType (..., AVMutableMovieLoadTracksCallback)' overload instead (or the 'LoadTracksWithMediaCharacteristic2Async' method).")]

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.

🤖 ❌ Binding definition — Copy-paste error in Obsolete message. This obsoletes LoadTracksWithMediaType, so it should refer to LoadTracksWithMediaType2Async, not LoadTracksWithMediaCharacteristic2Async.

Should be: [Obsolete ("Call the 'LoadTracksWithMediaType (..., AVMutableMovieLoadTracksCallback)' overload instead (or the 'LoadTracksWithMediaType2Async' method).")]

Rule: Obsolete messages must be helpful and accurate

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 AVFoundation LoadTrack*/LoadTracks* bindings whose completion-handler parameter types were incorrect by obsoleting the old signatures (pre-XAMCORE_5_0) and introducing correctly-typed overloads using named delegate callback types. This also updates bgen to preserve OverloadResolutionPriorityAttribute and adds tests/known-failure updates to cover the new APIs.

Changes:

  • Add correctly-typed LoadTrack*/LoadTracks* overloads (plus new named callback delegate types) and obsolete the incorrectly-typed variants behind !XAMCORE_5_0.
  • Teach bgen to recognize/emit OverloadResolutionPriorityAttribute and add the required implicit namespace.
  • Add monotouch runtime tests for the new APIs and update Documentation.KnownFailures.txt accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/monotouch-test/AVFoundation/AVAssetLoadTracksTest.cs Adds runtime coverage for the new LoadTrack*/LoadTracks* overloads on several AVFoundation types.
tests/cecil-tests/Documentation.KnownFailures.txt Updates the documentation known-failure allowlist for newly introduced (and newly obsolete) members/types.
src/bgen/Generator.cs Adds support for printing OverloadResolutionPriorityAttribute and treating it as a known binding attribute.
src/bgen/Caches/NamespaceCache.cs Adds System.Runtime.CompilerServices as an implicit namespace for generated code.
src/bgen/AttributeManager.cs Adds type-resolution support for System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.
src/avfoundation.cs Implements the corrected AVFoundation binding surface (new delegates, overloads, and obsoletions).

Comment thread src/avfoundation.cs
void LoadTrackWithMediaCharacteristics (string mediaCharacteristic, AVAssetLoadTracksCallback completionHandler);

#if !XAMCORE_5_0
[Obsolete ("Call 'LoadTracksWithMediaType (..., AVAssetLoadTracksCallback)' instead (or the 'LoadTracksWithMediaType' method).")]
Comment thread src/avfoundation.cs
AVMovieTrack [] GetTracks (AVMediaCharacteristics mediaCharacteristic);

#if !XAMCORE_5_0
[Obsolete ("Call the 'LoadTrack (..., AVMovieLoadTracksCallback)' overload instead (or the 'LoadTrack2Async' method).")]
Comment thread src/avfoundation.cs
#endif

#if !XAMCORE_5_0
[Obsolete ("Call the 'LoadTracksWithMediaType (..., AVMutableMovieLoadTracksCallback)' overload instead (or the 'LoadTracksWithMediaCharacteristic2Async' method).")]
Comment thread src/avfoundation.cs
void LoadTrack (int trackId, AVCompositionLoadTrackCallback completionHandler);

#if !XAMCORE_5_0
[Obsolete ("Call the 'LoadTracksWithMediaType (..., AVCompositionLoadTracksCallback)' overload instead (or the 'LoadTracksWithMediaType' method).")]
Comment thread src/avfoundation.cs
void LoadTracksWithMediaType (AVMediaTypes mediaType, AVCompositionLoadTracksCallback completionHandler);

#if !XAMCORE_5_0
[Obsolete ("Call the 'LoadTracksWithMediaCharacteristic (..., AVCompositionLoadTracksCallback)' overload instead (or the 'LoadTracksWithMediaCharacteristic' method).")]
Comment on lines +27 to +33
using var url = NSUrl.FromFilename (VideoPath);
using var asset = AVAsset.FromUrl (url);

var tcs = new TaskCompletionSource<AVAssetTrack?> ();
asset.LoadTrack2 (1, (track, error) => {
tcs.TrySetResult (track);
});
Comment on lines +9408 to +9412
M:AVFoundation.AVAsset.LoadTracksWithMediaType(AVFoundation.AVMediaTypes,AVFoundation.AVAssetLoadTracksCallback)
M:AVFoundation.AVAsset.LoadTracksWithMediaType(System.String,AVFoundation.AVAssetLoadTracksCallback)
M:AVFoundation.AVAsset.LoadTracksWithMediaType2Async(System.String)
M:AVFoundation.AVAsset.LoadTrackWithMediaCharacteristics(System.String,AVFoundation.AVAssetLoadTracksCallback)
M:AVFoundation.AVAsset.LoadTrackWithMediaCharacteristics2Async(System.String)
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #1f90e6a] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 1f90e6ae9f3ecc9f821b74ae930efdaa16172871 [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: 1f90e6ae9f3ecc9f821b74ae930efdaa16172871 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #1f90e6a] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 1f90e6ae9f3ecc9f821b74ae930efdaa16172871 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #1f90e6a] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 3 tests failed, 204 tests passed.

Failures

❌ monotouch tests (macOS)

1 tests failed, 19 tests passed.

Failed tests

  • monotouch-test/macOS/Debug (trimmable static registrar): Failed (Test run failed.
    Tests run: 3734 Passed: 3628 Inconclusive: 4 Failed: 1 Ignored: 105)

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

1 tests failed, 19 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug (LinkSdk): BuildFailure

Html Report (VSDrops) Download

❌ Tests on macOS Tahoe (26) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-arm64 monotouch-test: Failed (exit code 137)
    • No test failure details available. Output tail:
      • 2026-06-25 05:00:02.933 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:02.948 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:02.962 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:02.976 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:02.990 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:03.005 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:03.019 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:03.033 monotouchtest[29439:11048177] CFSocketSetAddress listen failure: 102
      • 2026-06-25 05:00:03.076 monotouchtest[29439:11047817] CFSocketSetAddress listen failure: 102
      • [PASS]

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 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): 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 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: 1f90e6ae9f3ecc9f821b74ae930efdaa16172871 [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.

AVAsset.LoadTracksWithMediaTypeAsync binding incorrect return type

3 participants