Repository navigation
Conversation
…g 2+ items (#37879) ### Description of Change `PickerResultsToMediaFiles` reads `PHPickerResult.ItemProvider` — a UIKit call guarded by `UIApplication.EnsureUIThread()` — inside a loop that awaits with `ConfigureAwait(false)`: ```csharp foreach (var file in results) { fileResult = new PHPickerFileResult(file.ItemProvider); // UIKit call await fileResult.LoadFileRepresentationAsync().ConfigureAwait(false); fileResults.Add(fileResult); fileResult = null; } ``` The first iteration runs on the main thread, because the picker delegate invokes it from the dismissal completion. But `LoadFileRepresentationAsync` completes through a `TaskCompletionSource<bool>` created with `TaskCreationOptions.RunContinuationsAsynchronously`, so the continuation never runs inline. From the second iteration onwards the read happens on the thread pool and throws `UIKitThreadAccessException`. This makes it deterministic rather than a race — picking 2 or more items always fails, picking 1 always works. This is a regression from #35805, which replaced the previous `Select(...).ToList()` materialization — where every `ItemProvider` was read before the first await — with the loop above. **Change:** read every `ItemProvider` up front, before the first await, then load the file representations in a second loop. `NSItemProvider` is a Foundation type with no UI-thread guard, so holding the providers across the awaits is safe. This preserves what #35805 set out to fix: `FullPath` is assigned in the `PHPickerFileResult` constructor via `CreateTemporaryFilePath`, not by the load, so it still points at a real temp-backed file. Ordering, image processing and video handling are untouched. It also fixes a leak in the error path: previously, when a load threw, results already constructed by earlier iterations were disposed, but ones constructed later were not. Results are now only added to the returned list once loaded, and any left unloaded by a failure are disposed separately. ### Verification - `dotnet format src/Essentials/src/Essentials.csproj --no-restore --include src/Essentials/src/MediaPicker/MediaPicker.ios.cs --verify-no-changes` — clean - `dotnet build src/Essentials/src/Essentials.csproj -f net10.0-ios26.0 --no-restore /p:BuildIpa=false /p:EnableSourceLink=false /p:UseSharedCompilation=false` — 0 warnings, 0 errors - `dotnet build src/Essentials/src/Essentials.csproj -f net10.0-maccatalyst26.0 --no-restore /p:EnableSourceLink=false /p:UseSharedCompilation=false` — 0 warnings, 0 errors - Ran on the iOS 26.4 simulator (iPhone 17) by dropping the built `Microsoft.Maui.Essentials.dll` into the repro app from the issue, so the real fixed code was exercised through `MediaPicker.Default.PickPhotosAsync`: - picking 3 photos no longer throws - every returned `FileResult.FullPath` exists, is non-empty, and `File.Copy(result.FullPath, ...)` succeeds — i.e. the #32832 scenario that #35805 fixed still works No unit test is included: the affected path needs a real `PHPickerResult`, which cannot be constructed in `Essentials.UnitTests`. Happy to add coverage if you can point me at a suitable seam. ### Issues Fixed Fixes #37878 (cherry picked from commit 11ed1ae) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo
temporarily deployed
to
copilot-pat-pool
September 11, 2026 22:40 — with
GitHub Actions
Inactive
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38465Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38465" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
kubaflo
temporarily deployed
to
copilot-pat-pool
September 11, 2026 22:40 — with
GitHub Actions
Inactive
kubaflo
temporarily deployed
to
copilot-pat-pool
September 11, 2026 22:42 — with
GitHub Actions
Inactive
kubaflo
temporarily deployed
to
copilot-pat-pool
September 11, 2026 22:45 — with
GitHub Actions
Inactive
kubaflo
temporarily deployed
to
copilot-pat-pool
September 11, 2026 22:45 — with
GitHub Actions
Inactive
kubaflo
temporarily deployed
to
copilot-pat-pool
September 11, 2026 22:46 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
UIKit threading changes warrant final human verification.
Pull request overview
Fixes iOS MediaPicker UIKit threading failures during multi-item selection and improves cleanup when loading fails.
Changes:
- Materializes item providers on the UI thread before asynchronous loading.
- Improves disposal of loaded and unloaded results on failure.
File summaries
| File | Description |
|---|---|
src/Essentials/src/MediaPicker/MediaPicker.ios.cs |
Updates provider loading and failure cleanup. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
This was referenced Sep 12, 2026
Contributor
Author
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
Forward-ports the merged fix from #37879 (
inflight/current) tomainfor #37878.PickerResultsToMediaFilespreviously read eachPHPickerResult.ItemProviderafter an awaited operation resumed on a thread-pool thread. Picking two or more items could therefore throwUIKitThreadAccessException. The fix materializes all item providers on the UI thread before the first await, then loads their file representations separately. It also disposes providers that remain unloaded if loading fails.SR11 Backport Sequence
This
mainforward-port must merge before the SR11 backport is created. After this PR merges, its merge commit can be backported torelease/10.0.1xx-sr11. No SR11 PR, release-ref push, or/backportrequest has been created yet.Provenance
Cherry-picked the single-parent squash merge commit
11ed1aeb65f7fd2fbfb0fed5de967380d7fa54a4from #37879 with explicit provenance. The patch applied without conflicts and has the same stable patch ID as the source (2097bc330feea531a113c4d3eb3a56cb0263f67a). Patch version 120 remains unchanged.Validation
dotnet format src/Essentials/src/Essentials.csproj --no-restore --include src/Essentials/src/MediaPicker/MediaPicker.ios.cs --verify-no-changesdotnet build src/Essentials/src/Essentials.csproj -f net10.0-ios26.0 --no-restore /p:BuildIpa=false /p:EnableSourceLink=false /p:UseSharedCompilation=falsedotnet build src/Essentials/src/Essentials.csproj -f net10.0-maccatalyst26.0 --no-restore /p:EnableSourceLink=false /p:UseSharedCompilation=falseBoth builds completed with 0 warnings and 0 errors. The original runtime verification remains documented in #37879.
Issues Addressed
#37878