unoplatform/uno · error · InvalidOperationException
Playlist Items could not be set
Error message
Playlist Items could not be set
What it means
InvalidOperationException thrown in InitializeSource (WebAssembly) when the source is a MediaPlaybackList with Items.Count > 0 but after SetPlaylistItems the _playlistItems list is null or empty — i.e. none of the playlist items produced a usable Uri. SetPlaylistItems maps each item to i.Source.Uri, so items with null Source/Uri yield no playable URI.
Source
Thrown at src/AddIns/Uno.UI.MediaPlayer.WebAssembly/MediaPlayerExtension.cs:310
return;
}
try
{
_owner.PlaybackSession.PlaybackState = MediaPlaybackState.Opening;
InitializePlayer();
switch (_owner.Source)
{
case MediaPlaybackList playlist when playlist.Items.Count > 0:
SetPlaylistItems(playlist);
if (_playlistItems is not null && _playlistItems.Any())
{
_uri = _playlistItems[0];
}
else
{
throw new InvalidOperationException("Playlist Items could not be set");
}
break;
case MediaPlaybackItem item:
_uri = item.Source.Uri;
break;
case MediaSource source:
_uri = source.Uri;
break;
default:
throw new InvalidOperationException("Unsupported media source type");
}
ApplyVideoSource();
Events?.RaiseSourceChanged();
}View on GitHub (pinned to 0418340488)
Solutions
- Ensure every MediaPlaybackItem in the list has a Source with a non-null Uri before assigning the playlist.
- Guard against concurrent modification: snapshot playlist.Items before the count check and the mapping.
- Filter out items with null Source/Uri before building the MediaPlaybackList.
- If using stream-backed sources, switch to Uri-backed MediaSource.CreateFromUri for WASM compatibility.
- Log each item's Source.Uri during construction to identify the offending entry.
Example fix
// before — items may have null Uri var list = new MediaPlaybackList(); list.Items.Add(new MediaPlaybackItem(MediaSource.CreateFromStream(stream, ""))); player.Source = list; // after — ensure Uri-backed items var list = new MediaPlaybackList(); list.Items.Add(new MediaPlaybackItem(MediaSource.CreateFromUri(new Uri(url)))); player.Source = list;
Defensive patterns
Strategy: validation
Validate before calling
// Ensure every playlist item has a Uri before assigning
if (playlist.Items.All(i => i?.Source?.Uri is not null))
player.Source = playlist;
else
throw new InvalidOperationException("Playlist contains items without a Uri"); Type guard
bool PlaylistHasPlayableUris(MediaPlaybackList list)
=> list.Items.Count > 0 && list.Items.All(i => i?.Source?.Uri is not null); Try / catch
try { player.Source = playlist; }
catch (InvalidOperationException ex) when (ex.Message.Contains("Playlist Items could not be set"))
{ Log.Error("Playlist produced no playable URI"); OnMediaFailed(ex); } Prevention
- Build playlists from Uri-backed MediaPlaybackItems only on WASM.
- Snapshot and validate Items before assignment to avoid races.
- Filter out items with null Source/Uri.
When it happens
Trigger: MediaPlayer.Source is a MediaPlaybackList whose items exist but each item's Source is null or Source.Uri is null; items were concurrently removed between the Count>0 check and SetPlaylistItems; playlist built with MediaPlaybackItems whose backing MediaSource has no Uri (e.g. stream-backed sources unsupported on WASM).
Common situations: Building a playlist from MediaPlaybackItems constructed without a Uri (e.g. from an IMediaSource/stream); concurrent mutation of the playlist; a deserialization path that created items with null Source. Note: a null Source.Uri would throw NullReferenceException inside SetPlaylistItems' Select rather than reach this guard, so the empty-list case implies items whose Uri resolved to nothing or were cleared.
Related errors
- MediaPlayerPresenterExtension must be initialized with a Med
- Unsupported media source type
- IStorageFile is not supported
- IMediaSource is not supported
- IRandomAccessStream is not supported
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/4470c2ee86c791dc.
Report an issue: GitHub.