unoplatform/uno · error · NotSupportedException

SetSurfaceSize is not supported

Error message

SetSurfaceSize is not supported

What it means

NotSupportedException thrown by MediaPlayerExtension.SetSurfaceSize on WebAssembly. The WASM media extension does not support explicit surface-size control (the HTML <video> element sizes via layout); calling SetSurfaceSize always throws.

Source

Thrown at src/AddIns/Uno.UI.MediaPlayer.WebAssembly/MediaPlayerExtension.cs:473

			if (this.Log().IsEnabled(LogLevel.Debug))
			{
				this.Log().Debug($"MediaPlayerExtension.Play(): Failed {ex}");
			}
			OnMediaFailed(ex);
		}
	}

	public void SetFileSource(IStorageFile file)
		=> throw new NotSupportedException($"IStorageFile is not supported");

	public void SetMediaSource(IMediaSource source)
		=> throw new NotSupportedException($"IMediaSource is not supported");

	public void SetStreamSource(IRandomAccessStream stream)
		=> throw new NotSupportedException($"IRandomAccessStream is not supported");

	public void SetSurfaceSize(Size size)
		=> throw new NotSupportedException($"SetSurfaceSize is not supported");

	public void SetUriSource(Uri uri)
	{
		if (this.Log().IsEnabled(LogLevel.Debug))
		{
			this.Log().Debug($"MediaPlayerExtension.SetUriSource({uri})");
		}

		if (_player is not null)
		{
			_player.Source = uri.OriginalString;
		}
	}

	public void StepBackwardOneFrame()
		=> throw new NotSupportedException($"StepBackwardOneFrame is not supported");

	public void StepForwardOneFrame()

View on GitHub (pinned to 0418340488)

Solutions

  1. On WASM, control size via the MediaPlayerElement's layout/CSS rather than SetSurfaceSize.
  2. Branch by platform: skip SetSurfaceSize on WASM.
  3. Guard the call site with OperatingSystem.IsBrowser().
  4. If a fixed size is required, set Width/Height on the hosting element instead.

Example fix

// before — shared size configuration
extension.SetSurfaceSize(new Size(640, 360));

// after — skip on WASM, size via layout
#if !__WASM__
    extension.SetSurfaceSize(new Size(640, 360));
#else
    mediaPlayerElement.Width = 640; mediaPlayerElement.Height = 360;
#endif
Defensive patterns

Strategy: validation

Validate before calling

// Do not call SetSurfaceSize on WASM; size via layout
if (!OperatingSystem.IsBrowser())
    extension.SetSurfaceSize(size);
else
    mediaPlayerElement.Width = size.Width;

Type guard

bool SupportsSetSurfaceSize() => !OperatingSystem.IsBrowser();

Try / catch

try { extension.SetSurfaceSize(size); }
catch (NotSupportedException ex) when (ex.Message.Contains("SetSurfaceSize"))
{ Log.Error("SetSurfaceSize unsupported on WASM — size via layout"); }

Prevention

When it happens

Trigger: Calling SetSurfaceSize(Size) on the WASM media extension from shared code that configures a fixed rendering surface size.

Common situations: Cross-platform code that sets a surface size for native video rendering; porting desktop behavior to WASM where size is driven by CSS/layout.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/3e5c83b29915a8e4. Report an issue: GitHub.