Visual Studio stops working after patch upgrade and "dotnet --list-sdks" shows no results

My VS Community 2019 stopped working after upgrading to latest, none of my projects could be loaded in VS after the upgrade. This is what I saw when I opened a simple web project.

VS cannot load any project after upgrade
VS cannot load any project after upgrade

The VS screenshot above was v16.9.1, but the exact same problem had happened once before after I upgraded to v16.9.0. Last time I re-installed VS to get around, this time even a re-install wouldn't do it. And a few days ago v16.9.2 came out and upgrading to v16.9.2 did not fix it either. Plus, none of my projects regardless type, console, web etc. were able to load. I opened up an issue on VS Developer Community forum.

Today I was trying to running my project from VS Code and dotnet.exe wasn't working from command prompt. So I fixed that and in turn I got my VS fixed.

No SDKs were found

Issue: When I execute dotnet --list-sdks at a cmd it shows nothing, but if I go to Apps & features on Windows it shows I do have SDK v5 installed.

dotnet --list-sdk shows nothing
dotnet --list-sdk shows nothing

Diagnosis: This could be the dotnet.exe that is running is from C:\Program Files (x86)\dotnet\dotnet.exe instead of C:\Program Files\dotnet\dotnet.exe. To be sure it's the case, run

"C:\Program Files\dotnet\dotnet.exe" --list-sdks

For me this shows 5.0.104 which is expected since App & features does show I have it installed.

Solution: Since the default dotnet.exe that I'm running is the x86 version (first in %PATH% probing order), the solution is to remove it from the Environment Variable.

  1. Windows + Pause/Break will bring up the System Page
  2. click on Advanced system settings on the sidebar
  3. check Path variable on both User and System sections

My "User variables" didn't have any entries for dotnet, but my "System variables" has both the following with the x86 first on top of the x64.

"C:\Program Files (x86)\dotnet",
"C:\Program Files\dotnet"

I simply delete the x86 entry and restart my bash cmd, then dotnet --list-sdks outputs 5.0.104.


Install ".NET desktop development" workload

VS warning to install extra components
VS warning to install extra components

After I fixed dotnet.exe for command prompt, the simple web project I created for testing was able to work. But my Fanray solution still could not, VS showed a warning that asked me to install extra component. Clicking on the "Install" link, the VS installer came up and asked me to install the ".NET desktop development" workload. Pretty weird I thought since I'm not sure what part of my webapp uses anything desktop related, but installing this workload worked for me.

If it's just a simple matter of dotnet.exe being used is from the wrong path, then I don't understand why VS behaved the way it did, showing this error message “Error HRESULT E_FAIL has been returned from a call to a COM component” (see the first screenshot) and asking me to install desktop workload which I never installed previously and everything was working till the recent upgrades.