Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'XOpenDisplay failed' error under WSL2 Ubuntu-22.04 (WSL1 Ubuntu 20.04 works fine) #9373

Closed
bairog opened this issue Nov 7, 2022 · 8 comments
Labels

Comments

@bairog
Copy link

bairog commented Nov 7, 2022

Describe the bug
When I try to run an application create from a template on WSL2 Ubuntu-22.04 it fails with the following error:

Exception thrown: 'System.Exception' in Avalonia.X11.dll
An unhandled exception of type 'System.Exception' occurred in Avalonia.X11.dll: 'XOpenDisplay failed'
Stack trace:
 >   at Avalonia.X11.AvaloniaX11Platform.Initialize(X11PlatformOptions options)
 >   at Avalonia.Controls.AppBuilderBase`1.Setup()
 >   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode)
 >   at AvaloniaApplication1.Program.Main(String[] args) in D:\AvaloniaApplication\AvaloniaApplication1\Program.cs:line 12

WSL1 Ubuntu-20.04 starts correctly.
I have Windows 10 Pro 21H2 and Visual Studio 2022 Pro 17.3.6. My WSL distros:
image
My launchSettings.json:

{
  "profiles": {
    "AvaloniaApplication1": {
      "commandName": "Project"
    },
    "WSL1 - Ubuntu-20.04": {
      "commandName": "WSL",
      "environmentVariables": {
        "DISPLAY": ":0" //,
        //"GDK_GL": "gles" // use this line when running under WSL on Windows 11
      },
      "distributionName": "Ubuntu-20.04"
    },
    "WSL2 - Ubuntu-22.04": {
      "commandName": "WSL",
      "environmentVariables": {
        "DISPLAY": ":0" //,
        //"GDK_GL": "gles" // use this line when running under WSL on Windows 11
      },
      "distributionName": "Ubuntu-22.04"
    }
  }
}

I use "commandName": "WSL" not "WSL2" as MS article states that:

Starting in Visual Studio 2022 Preview 3, the command name in the Launch Profile changed from WSL2 to WSL.

I use vcXsrv (an X11 server for Windows) and start it in "Multiple windows" mode and then "no client" mode.

Desktop (please complete the following information):

  • OS: WSL2 Ubuntu-22.04
  • Version: 0.10.18

Additional context
Reproduced only under WSL2, works fine on WSL1 and normal Ubuntu.

@bairog bairog added the bug label Nov 7, 2022
@timunie
Copy link
Contributor

timunie commented Nov 7, 2022

Hi @bairog

From this link I learned that in the newer version Ubuntu uses Wayland: https://linuxconfig.org/how-to-enable-disable-wayland-on-ubuntu-22-04-desktop

We have a PR for supporting this open, see #8352 . Maybe you can try this PR out on your machine?

@bairog
Copy link
Author

bairog commented Nov 7, 2022

Hi @timunie

From this link I learned that in the newer version Ubuntu uses Wayland: https://linuxconfig.org/how-to-enable-disable-wayland-on-ubuntu-22-04-desktop

Do I understand correctly that WSL does not have GUI, so /etc/gdm3/custom.conf doesn't exist, which means that I cannot switch default Wayland back to X11?

We have a PR for supporting this open, see #8352 . Maybe you can try this PR out on your machine?

I've downloaded that PR but looks like project targets .NET 7.0 RC2. We are prohibited to use prerelease versions of .NET SDKs in our company - so I will try again tomorrow evening when Visual Studio 2022 17.4.0 and .NET 7.0 will be released :)

@timunie
Copy link
Contributor

timunie commented Nov 7, 2022

Do I understand correctly that WSL does not have GUI, so /etc/gdm3/custom.conf doesn't exist, which means that I cannot switch default Wayland back to X11?

Sorry, that's beyond my knowledge.

@kekekeks
Copy link
Member

kekekeks commented Jul 3, 2023

Missing X11 display is an issue with WSL (most likely misconfigured) itself, not Avalonia

@kekekeks kekekeks closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2023
@mikelor
Copy link

mikelor commented Jul 13, 2024

@kekekeks and @timunie Other GUI apps work on WSL with Ubuntu 22.04. I filed an issue on microsoft/wsl to report an issue with Git Credential Manager which fails for with this same error. Chrome runs fine. I also reported this issue on Git Credential Manager

I just downloaded and tried to run Chronify another Avalonia based app and it fails just like Git Credential Manager.

The common thread with this error is that they are both Avalonia based.

This was not an issue in WSL 2.1.5

@maxkatz6
Copy link
Member

@mikelor Avalonia doesn't do anything special, but opens a display connection https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.X11/X11Platform.cs#L57. Something like this should work on properly configured machine. Let's see what WSL response is.

@mikelor
Copy link

mikelor commented Jul 13, 2024

So, I found the issue. Looks like a change in WSL's networking and DNS Tunneling as described here.
microsoft/WSL#11698 (comment)

export DISPLAY=$(ip route | grep default | awk '{print $3}'):0.0

Thanks for reading.

@timunie
Copy link
Contributor

timunie commented Jul 13, 2024

@mikelor I'm not using wsl rn, so can't judge on my own. Do you think this change should be on Avalonia side? If so, so may want to provide a PR to help others as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants