microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.67k stars 292 forks source link

`Code.exe: Invalid argument` after upgrading to Windows 11 #7050

Open jared-thoughtbot opened 2 years ago

jared-thoughtbot commented 2 years ago

Steps to Reproduce:

  1. Ignore Windows 11 upgrade prompts for ages
  2. Upgrade to Windows 11
  3. Open terminal in WSL2 linux distro
  4. Navigate to a repo
  5. Type code . to launch VSCode

What you expected to see:

VSCode opens in remote mode

What you saw instead:

$ code .
/mnt/c/Users/jared/AppData/Local/Programs/Microsoft VS Code/Code.exe: Invalid argument

Notes

I appreciate there's not a lot of info here. Please let me know what I can do to help troubleshoot this further.

jared-thoughtbot commented 2 years ago

This seems to have fixed itself 🤷‍♂️ I have no idea what changed so can't provide further context but going to close this now.

jared-thoughtbot commented 2 years ago

This issue has re-appeared again, seemingly after another restart. Happy to help debug this in any way I can.

kp1dell commented 1 year ago

I just migrated to Windows 11 and see the exact same issue.

I migrated my entire WSL from my older laptop using it's export/import feature and installed a fresh copy of Visual Studio Code along with WSL extension and now can't get this very important feature, for me, working. See screenshot below

image
teichert commented 1 year ago

In my case, this was related to this WSL issue, and the suggestion to wsl --shutdown from the windows command prompt fixed my issue at least temporarily. (After starting wsl again, code works as expected again.) However, it does seems to break again sometimes, and I don't see a consistent pattern with what causes it to break.

revoyrm commented 1 year ago

This is also consistently happening to me as well. On Windows 11, new computer, not and upgrade. It isn't just code . that doesn't work. Similar commands like explorer.exe . give the same error.

wsl --shutdown works for a little bit but it always breaks again.

apkatsikas commented 1 year ago

suffering from this since windows 11 update. no idea what to do

apkatsikas commented 1 year ago

suffering from this since windows 11 update. no idea what to do

my solution was to uninstall/reinstall vscode. hopefully it lasts

yooakim commented 1 year ago

I have the same issue as reported here. For me wsl --shutdown resolved the problem. (Windows 11 version 10.0.22621)

I am using VS Code:

1.81.1
6c3e3dba23e8fadc360aed75ce363ba185c49794
x64

WSL distro:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy
GraueEminenz79 commented 1 year ago

Imho, this is not due to a Windows 11 upgrade but a WSL update: it happens to me frequently on Win 10, too. And "frequently" really means that it works at first for a few minutes/hours/... and then out of a sudden stops to work. Annoying! Btw, in my impression everything™ under /mnt/c/ is not working from there onwards (had my AZ CLI installed in Windows instead of WSL, failing too)

leandroauzier commented 1 year ago

im not using windows 11 but had to reinstall it again Ubuntu 20.04, and when type code . gives me

/mnt/c/Users/leand/AppData/Local/Programs/Microsoft VS Code/Code.exe: Invalid argument

I've tried the wsl --shutdown command but it continues the same, and even trying to reload WSL extension, so the only way i can is opening VSCode and acessing host from there

abdullzz commented 11 months ago

this issue still persist till today, need a follow up, anyone?

ghost commented 10 months ago

Strange thing is, it works when i navigate to the program folder and then execute the program. But when i execute the program from another folder with absolute program path, it doesn't. By the way it is not only with vscode but every windows program which is mounted in WSL

lulzhipsters commented 10 months ago

I'm also experiencing the same problem, wsl --shutdown has yet to resolve the issue

kokakin commented 10 months ago

Using W11 updated as of last week. For me the issue was WSL had to have administrator privileges. Without it, the same error occurred, with it the command code works. My guess is that something during VSCode installation made it administrator only, which impedes wsl to access it without such privileges.

hmenorjr commented 9 months ago

This worked for me as of this writing:

  1. Reinstall VSCode (latest version)
  2. Ran wsl --shutdown
>wsl --version
WSL version: 2.0.9.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
chazwilder commented 8 months ago

The issue was resolved for me when turned off "Run As Admin"

image

image

divinity76 commented 8 months ago

I also had this problem, I had success with running wsl --shutdown + start WSL as administrator 🤔

tutunak commented 7 months ago

Same problem

leandroauzier commented 7 months ago

i forgot to mention that the palliative measure that i found was to remove vscode-server and shutdown wsl:

rm -r ~/.vscode-server then on cmd or powershell: wsl --shutdown

and then boot again with code . command to reinstall vscode

sherlockyzd commented 7 months ago

The issue was resolved for me when turned off "Run As Admin"

image

image

It does work well, thx!!!

AhmadYousif89 commented 7 months ago

Just running the wsl terminal (Ubuntu) as administrator fixed the issue for me. you can temporarily right click on the app and run as administrator or for permanent solution go to the WSL folder on this path: C:\Program Files\WSL and make the wsl.exe file to always run as administrator from the compatibility tab check the image below

wsl

Specifications:

WSL version: 2.1.5.0 Distro: Ubuntu-22.04 Kernel version: 5.15.146.1-2 OS: Windows_NT x64 10.0.19045

MatchalatteR commented 7 months ago

The issue was resolved for me when turned off "Run As Admin"

image

image

It works for me, thanks!

andersonlobo98 commented 7 months ago

O problema foi resolvido para mim quando desativei "Executar como administrador"

imagem

imagem

Thank you, works here

seojunchian commented 5 months ago

Fixed the problem with opening ubuntu in administrator hope it works for you too but I downloaded ubuntu through wsl than restarted it than administrator part just in case.

habsfanongit commented 1 month ago

Any other solution beisdes running vscode as an admin? in most corp, the admin option is not a solution.

vkviyu commented 1 month ago

The root cause of this issue lies in the permission management and process isolation mechanisms between Windows and WSL. When you run code.exe as an administrator, processes running as a regular user in WSL cannot interact with the elevated process. This leads to the code command in WSL failing to start Visual Studio Code correctly.

Detailed Explanation

  1. Permission Isolation: In Windows, there is permission isolation between processes running as an administrator and those running as a regular user. Regular user processes cannot directly interact with administrator processes. This is a security measure to prevent unauthorized operations by regular user processes.

  2. WSL and Windows Process Interaction: Processes in WSL typically run with regular user permissions. When you run the code . command in WSL, it attempts to start a new code.exe process. If code.exe is already running as an administrator, the regular user process in WSL cannot interact with this elevated process, leading to the error.

Solutions

To avoid this issue, you can choose from the following solutions:

  1. Do Not Run VS Code as Administrator: Ensure that code.exe is not running as an administrator. This way, regular user processes in WSL can start and interact with code.exe normally.

  2. Run WSL as Administrator: If you need to run VS Code as an administrator, you can try running WSL as an administrator. This can be done with the following steps:

    • Right-click the Windows Start menu and select "Windows PowerShell (Admin)" or "Command Prompt (Admin)".
    • Start WSL from the elevated PowerShell or Command Prompt:
      wsl
    • Now run the code . command in WSL.
  3. Use VS Code Remote - WSL Extension: This extension allows you to seamlessly use VS Code within WSL without worrying about permission issues. Ensure you have installed VS Code and the Remote - WSL extension, then run the following command in WSL:

    code .

    This will start VS Code and connect to the WSL environment.

By following these methods, you should be able to avoid permission issues and use the code command in WSL without any problems.

DJ-Yosef commented 2 days ago

关闭“以管理员身份运行”后,此问题已为我解决

image

image

The issue was resolved for me when turned off "Run As Admin"

image

image

This works in mine.As the saying goes :“Every cause has its effect.”A few days ago I ticked exactly this Run-As-Admin-option in order to install an extension for VSCode. If this solution holds true for you as well, in order to permanently solve similar possible problems, I would suggest that you assign permissions to the root directory where VSCode is located (e.g., 'D:\Program Files') to your usual users instead of just administrators (of course, you need to make sure that you know what you're doing).