VS Code connect to WSL Ubuntu 20.04 LTS, fail with error: Could not fetch remote environment

33.9k views Asked by At

A few days ago I was working just fine with VS Code connected to WSL Ubuntu 20.04, then I did some updating on WSL, Ubuntu 20.04 LTS and VS Code and now I can not connect to WSL 20.04, and I always got those two messages, even when no folder/workspace is selected/open.

Could not fetch remote environment

Failed to connect to the remote extension host server (Error: Connection error: Unauthorized client refused.)

When I try to open a folder it shows the folder structure but it always said that: The path does not exists. And does not show any file in it but I can follow the folder structure up and down just fine.

And on the other hand if I launch WSL with an older Ubuntu 18.04 distro, it works just fine.

I imagine there is some security setting or access list that is wrong, but I can not figure it out, and web searching has not help either.

Any idea what to do to get it working again ?.

13

There are 13 answers

0
Luis Carlos Burgos On

Just in case somebody else run into this problem. The way I solved was to remove all the .vscode* folders/files on the WSL filesystem. Apparently something got screw up on the upgrade.

I have not test it fully, because I moved to directly using a remote ssh agent on the Test system. But it seems to work, as I can now open the wsl window and it does not report any error.

0
xianshenglu On

For me, turning off the proxy will work.

enter image description here

or add 127.0.0.1 in the exception list.

4
Saurav On

I had the same error. And solved it by just shutting down the wsl using command

wsl --shutdown

0
Vishnu KR On

I had the same issue, after updating the version(1.52.1). I did uninstall the ms-vscode-remote.remote-wsl and installed it again and shutdown the WSL and close the vscode. Then started the WSL and open the VS-code again solved the issue.

0
Luis Felipe On

What worked for me on Win10:

opens Ubuntu CLI -> type in code .

It'll download the VSCode server and then open VSCode itself with no errors.

I tried the same on CMD or Powershell but it didn't work.

2
Calos On

I've tried these methods but it doesn't work:

  • wsl --shutdown
  • Reinstall VScode
  • Remove .vscode-server in WSL (rm -rf ~/.vscode-server)

Finally I found the problem, the problem was with the latest version of the WSL extension, downgrading the WSL extension worked for me.

I downgraded the extension version from v0.79.5 to 0.79.4, and after reloading the window everything was back to normal.

enter image description here

enter image description here

0
Xiang ZHU On

I ran to the same problem today, my solution was to rollback to previous VScode version. I know there might be multiple root causes, this is one of the them.

1
Sören Köhler On

Another (additional) symptom to check: Can WSL connect to the internet (eg via apt update)?

I had compressed my AppData folder, including C:\Users\<yourname>\AppData\Local\Temp and this somehow broke the connection between WSL and the outer world. Uncompressing the Temp folder solved the problem for me.

1
Sanchit Kashyap On

Lowering down the version of Remote WSL extension: ms-vscode-remote.remote-wsl worked out for me.There might be some issues with the latest version.

0
Yonas Neghusse On
sudo apt update

shoud work fine.

2
tallwithknees On

Seems things got messed up with the update. Fixed it by reinstalling the Remote WSL extension: ms-vscode-remote.remote-wsl and reloading as you will be instructed to do.

Before this though, I deleted (rm -rf) the contents of /home/<your_username>/.vscode-server/ bin/ and data/

0
kmrk On

On Windows OS restarting the computer can usually resolve strange issues.

Because sometimes there maybe other processes still using the files or connection.

2
limi58 On

Same problem, just quite the proxy software (Charles etc.) and restart the vscode, it will work fine