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

Mono Breaks WSL Interop #8531

Closed
1 of 2 tasks
reynoldsbd opened this issue Jun 20, 2022 · 6 comments
Closed
1 of 2 tasks

Mono Breaks WSL Interop #8531

reynoldsbd opened this issue Jun 20, 2022 · 6 comments

Comments

@reynoldsbd
Copy link
Member

Version

Microsoft Windows [Version 10.0.22000.739]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.102.1-microsoft-standard-WSL2

Distro Version

Ubuntu 20.04

Other Software

mono-runtime, version 6.12.0.182-0xamarin1+ubuntu2004b1

Installed from APT source provided by upstream Mono project as documented here.

Reason I need latest Mono is so I can use NuGet.exe on Linux. This is the officially documented workflow for using NuGet on macOS/Linux.

Repro Steps

  1. Within WSL, install mono-complete package according to the Mono project's instructions (linked above)
  2. Within WSL, run the command notepad.exe

Expected Behavior

I expect to se the Notepad application start.

Actual Behavior

Notepad does not start, and the following is printed in my terminal:

user@host:~$ notepad.exe
Cannot open assembly '/mnt/c/windows/system32/notepad.exe': File does not contain a valid CIL image.
user@host:~$

I believe this is because the mono-runtime package is installing a new binary format (named cli) which matches any PE executable file or DLL.

I can work around by running the following command:

user@host:~$ sudo update-binfmts --disable cli

Diagnostic Logs

No response

@reynoldsbd
Copy link
Member Author

Credit for workaround comes from here. I am opening this as a new issue because that issue was closed and appears to be ignored.

cc @benhillis who participated in the initial conversation.

@elsaco
Copy link

elsaco commented Jun 21, 2022

When installing mono on Linux it registers a new interpreter with binfmt_misc:

tux@RIPPER:~$ update-binfmts --display cli
cli (enabled):
     package = mono-runtime
        type = magic
      offset = 0
       magic = MZ
        mask =
 interpreter = /usr/bin/cli
    detector = /usr/lib/cli/binfmt-detector-cli

Notice the magic = MZ, notepad.exe has the same file signature 0x4D5A:

tux@RIPPER: xxd /mnt/c/Windows/system32/notepad.exe
00000000: 4d5a 9000 0300 0000 0400 0000 ffff 0000  MZ..............

so mono is trying to run it, however notepad is a win32 not .net application, thus the error.

As mention above and other posts cli can be unregistered with update-binfmts --disable cli

wsl --shutdown works also.

@benhillis
Copy link
Member

This is by design. Mono is overwriting the WSL binfmt interpreter, there is nothing we can do about that.

@Biswa96
Copy link

Biswa96 commented Jun 24, 2022

Can init detect/distinguish native vs. managed PE?

@benhillis
Copy link
Member

The problem is with mono registering a binfmt with magic = MZ, WSL will never get invoked. The kernel will use whatever interpreter was registered last.

@viceice
Copy link

viceice commented Sep 17, 2022

update-binfmts --disable cli doesn't work on wsl with ubuntu 22.04 (upgraded from 20.04). I needed to remove mono completely (installed by nuget) and restart wsl.

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

No branches or pull requests

5 participants