unoplatform/uno · critical · InvalidOperationException

XLIB ERROR: Cannot connect to X server

Error message

XLIB ERROR: Cannot connect to X server

What it means

InvalidOperationException thrown by X11MediaPlayerPresenterExtension's constructor when XLib.XOpenDisplay(IntPtr.Zero) returns IntPtr.Zero, meaning no X server connection could be established. On the Skia/X11 target, the media player extension needs its own X display to host the LibVLC window. Without a display, native video hosting is impossible.

Source

Thrown at src/AddIns/Uno.UI.MediaPlayer.Skia.X11/X11MediaPlayerPresenterExtension.cs:36

{
	private readonly MediaPlayerPresenter _presenter;
	private SharedMediaPlayerExtension? _playerExtension;
	private readonly X11Window _x11Window;

	public X11MediaPlayerPresenterExtension(MediaPlayerPresenter presenter)
	{
		_presenter = presenter;

		IntPtr display = XLib.XOpenDisplay(IntPtr.Zero);
		using var lockDisposable = X11Helper.XLock(display);

		if (display == IntPtr.Zero)
		{
			if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error))
			{
				this.Log().Error("XLIB ERROR: Cannot connect to X server");
			}
			throw new InvalidOperationException("XLIB ERROR: Cannot connect to X server");
		}

		int screen = XLib.XDefaultScreen(display);

		_ = XLib.XFlush(display); // unnecessary on most Xlib implementations

		if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace))
		{
			this.Log().Trace("Created media player window.");
		}

		_x11Window = new X11Window(display, XLib.XCreateSimpleWindow(
			display,
			XLib.XRootWindow(display, screen),
			0,
			0,
			1,
			1,

View on GitHub (pinned to 0418340488)

Solutions

  1. Set DISPLAY correctly (export DISPLAY=:0) and ensure an X server is running.
  2. In headless/CI, run under Xvfb: xvfb-run ./app or start Xvfb and point DISPLAY to it.
  3. On Wayland, ensure XWayland is installed and enabled.
  4. For SSH, use ssh -X (or -Y) to forward X11, or run locally.
  5. If media playback isn't needed, avoid instantiating MediaPlayerPresenter on X11; guard behind a capability check.

Example fix

# before — headless run
./MyUnoApp

# after — provide a virtual X server
xvfb-run -a ./MyUnoApp
# or
Xvfb :99 & export DISPLAY=:99 && ./MyUnoApp
Defensive patterns

Strategy: validation

Validate before calling

// Verify an X display is reachable before constructing the X11 media extension
if (Environment.GetEnvironmentVariable("DISPLAY") is { } d && XLib.XOpenDisplay(IntPtr.Zero) != IntPtr.Zero)
    _presenter = new X11MediaPlayerPresenterExtension(mediaPresenter);
else
    Log.Error("No X server available; set DISPLAY or run under Xvfb.");

Type guard

bool XServerAvailable()
    => Environment.GetEnvironmentVariable("DISPLAY") is not null
       && XLib.XOpenDisplay(IntPtr.Zero) != IntPtr.Zero;

Try / catch

try { _presenter = new X11MediaPlayerPresenterExtension(mediaPresenter); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Cannot connect to X server"))
{ Log.Error("X11 unavailable — install/run Xvfb or set DISPLAY."); }

Prevention

When it happens

Trigger: Constructing X11MediaPlayerPresenterExtension (media playback on Skia Linux/X11) when DISPLAY is unset or points to an unreachable/non-existent X server; running headless (no X server, no Xvfb); SSH session without X forwarding; Wayland-only session without XWayland.

Common situations: CI/containers running the Skia X11 app without Xvfb; misconfigured DISPLAY=:0 on a headless server; Wayland environment where XWayland isn't available; SSH without -X; a systemd service without display access. The error is also logged before throwing.

Related errors


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