Skip to content

WSL2 - Microsoft VS Code/Code.exe: Exec format error #40537

Closed

Description

Windows Version

Microsoft Windows [Version 10.0.26200.8457]

WSL Version

2.6.3.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

6.6.87.2-1

Distro Version

Ubuntu 26.04 / Ubuntu 24.04

Other Software

No response

Repro Steps

If you open VS code with the classic command

code .

on a distro, then, if you switch distro, you get the error

grufoony@Gregorio:~$ code .
/mnt/c/Users/Gregorio/AppData/Local/Programs/Microsoft VS Code/bin/code: 62: /mnt/c/Users/Gregorio/AppData/Local/Programs/Microsoft VS Code/Code.exe: Exec format error

I noticed that if you do not call code on the other distro or you:

  • call code command on distro 1
  • reboot
  • call code command on distro 2

it is apparently working

Expected Behavior

See above

Actual Behavior

See above

Diagnostic Logs

WslLogs-2026-05-14_10-27-14.tar.gz

Activity

  1. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    Logs are required for review from WSL team

    If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
    Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

    How to collect WSL logs

    Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

    Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
    Set-ExecutionPolicy Bypass -Scope Process -Force
    .\collect-wsl-logs.ps1
    

    The script will output the path of the log file once done.

    If this is a networking issue, please use .\collect-wsl-logs.ps1 -LogProfile networking instead, following the instructions in Collect WSL logs for networking issues

    Once completed please upload the output files to this GitHub issue.

    See Collect WSL logs (recommended method).

    If you choose to email these logs instead of attaching them to the bug, please send them to [email protected] with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.

  2. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    The log file doesn't contain any WSL traces. Please make sure that you reproduced the issue while the log collection was running.

    Diagnostic information
    Issue was edited and new log file was found: https://github.com/user-attachments/files/27750937/WslLogs-2026-05-14_10-27-14.tar.gz
    .wslconfig found
    Detected appx version: 2.6.3.0
    Found no WSL traces in the logs
    
  3. benhillis commented on May 14, 2026

    @benhillis
    Member

    I've seen a few reports of this, but I haven't been able to determine a repro. Do you have repeatable steps to get into this state?

  4. Grufoony commented on May 14, 2026

    @Grufoony
    Author

    The only way I was able to reproduce this is:

    • Have both Ubuntu 24.04 and 26.04 installed
    • Open Ubuntu 24.04
    • Launch code . command (it should work)
    • Open Ubuntu 26.04
    • Launch code . command -> now it should be broken

    It has been a week since I have both distro installed and I'm dealing with this issue every day when I start the PC... once fixed it seems to be good until the next reboot

  5. gorgsenegger commented on May 18, 2026

    @gorgsenegger

    I get exactly the same error on Windows 11, WSL version 2.7.3.0 after installing Ubuntu 26.04 in addition to 22.04.

  6. added
    wsl2
    on May 29, 2026
  7. benhillis commented on May 29, 2026

    @benhillis
    Member

    Tracked this down. WSLInterop lives in binfmt_misc, which is kernel-global across the whole WSL2 VM, so all your distros share one registry. When a systemd distro shuts down cleanly, systemd-shutdown runs disable_binfmt(), which wipes every entry including WSLInterop for all running distros. That's why running code in a second distro breaks the first, and why a reboot fixes it until the next time.

    It was introduced by clean systemd termination (#13552) and is fixed by #40621, which will be in an upcoming release.

  8. kenden commented on Jun 8, 2026

    @kenden

    Until the next version with the fix is released, the workaround described here seems to help:

    $  sudo sh -c 'echo :WSLInterop:M::MZ::/init:PF > /usr/lib/binfmt.d/WSLInterop.conf'
    # [sudo] password for $USER:
    $  sudo systemctl unmask systemd-binfmt.service
    $  sudo systemctl restart systemd-binfmt
    $  sudo systemctl mask systemd-binfmt.service
    # Created symlink /etc/systemd/system/systemd-binfmt.service → /dev/null.
  9. chemwolf6922 commented on Jun 30, 2026

    @chemwolf6922
    Contributor

    Fixed in 2.9.3 (pre-release)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixinboundinteropwsl2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions