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

14

27

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 ?.

Automobile answered 29/9, 2020 at 17:57 Comment(0)
A
47

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

wsl --shutdown

Aretta answered 23/1, 2021 at 9:20 Comment(4)
Well, that did not work in my case. Even restarting the computer did not solved anything.Automobile
This worked for me and then I followed the wsl --shutdown command with the command wsl --update.Gam
worked here. wsl --shutdown followed by wsl to start the os again.Ingest
this worked and then I needed to reinstall the WSL extension. :)Lisa
G
13

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/

Gauger answered 27/12, 2020 at 16:44 Comment(2)
The removal of previous .vscode* directories is the most likely solution for this issue.Automobile
tried all the proposals, but nothing worked. also reinstalled the remote extensions and rm the .vscode-server as here mentioned without success. but after reseting this extension "ms-vscode-remote.vscode-remote-extensionpack" to an older version and updating the extension, it worked again.Technetium
D
9

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

Despotic answered 30/6, 2023 at 11:6 Comment(2)
If anyone wondering how to uninstall rm ~/.vscode-server inside wslAngeloangelology
For anyone who doesn't seem to find it working. Make sure you close all the VS code instances. I tried this solution once it worked fine, the second time it didn't. Turns out according to a GitHub Issues you have to close all the vs code instances, even though you already run wsl --shutdown it's not enough.Veriee
C
5

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.

Cannell answered 13/7, 2021 at 8:27 Comment(1)
Worked for me, as well. "Visual Studio Code Remote - WSL" version 0.58.4 did not work for me. 0.85.3 works for me.Fotinas
A
4

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.

Aurelea answered 18/3, 2021 at 1:53 Comment(1)
Search for the %temp% directory, go to properties -> general -> advanced -> uncheck compress contents to save disk space. I also needed a system restart but after that, it was working.Gastro
P
2

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.

Prajna answered 25/1, 2021 at 18:3 Comment(0)
A
2

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.

Ascospore answered 23/11, 2022 at 14:16 Comment(0)
A
1

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.

Automobile answered 19/10, 2020 at 17:27 Comment(1)
Worked here too, but I also had to quit all VSCode instancesIdiom
C
0
sudo apt update

shoud work fine.

Croom answered 18/5, 2023 at 19:16 Comment(0)
M
0

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.

Martins answered 18/7, 2023 at 8:11 Comment(0)
C
0

For me, turning off the proxy will work.

enter image description here

or add 127.0.0.1 in the exception list.

Conceit answered 28/11, 2023 at 7:25 Comment(0)
Z
0

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

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

Zircon answered 28/12, 2023 at 7:8 Comment(0)
F
0

So am just giving input on what worked for me recently Yes I also agree with the fact that there's something that went wrong in the upgrading of wsl extension but so far at this current moment haven't had issues with this problem arising. steps i took was

  1. Closed my wsl also run wsl --shutdown in powershell or whatever...
  2. Uninstall VsCode ( a step i skipped but for good measure delete the userdata/OR.../.vscode/extensions folder as well).
  3. I think this is the crucial part do not download from the vscode site rather download VsCode within the Microsoft Store. (if it fails keep trying).

For me i did try the above mentioned and other sources but was just temp for my case. but this time following these steps so far hasn't given me problems 2days beats every 30min in my view

Flyspeck answered 15/5 at 21:22 Comment(0)
D
-3

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

Distich answered 4/11, 2021 at 3:26 Comment(2)
In my case there was no proxy software, just WSL and VSC with a bunch of extensions.Automobile
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewFelicle

© 2022 - 2024 — McMap. All rights reserved.