Cleaning up corrupt Visual Studio instances

A small number of users are seeing errors after installing or modifying Visual Studio 2017 like the following,

Sorry, the installation failed. Please try again.

This may also manifest in some cases as,

A product matching the following parameters cannot be found:

channelId: VisualStudio.15.Release
productId: Microsoft.VisualStudio.Product.Enterprise

If you open the latest %TEMP%\dd_client*.log file you may see an exception stack trace like,

2017-08-07T03:20:00 : Error : Failed to get installed product summaries. [installerId: SetupEngine, error: System.NullReferenceException: Object reference not set to an instance of an object.
  at Microsoft.VisualStudio.Setup.Cache.InstanceRepository.GetInstance()
  at Microsoft.VisualStudio.Setup.Cache.CacheRepository.d__32.MoveNext()
  at Microsoft.VisualStudio.Setup.InstalledProductsProviderService.GetInstalledProductSummariesImpl()
  at Microsoft.VisualStudio.Setup.InstalledProductsProviderService.GetInstalledProductSummaries()

Subsequent operations in the Visual Studio Installer fail, and if you reopen the Visual Studio Installer you may not see any instances installed – only what products are available.

Solution

We have mitigated a couple of possible causes and continue to explore both mitigations and long-term remedies, but in the meantime, you will need to clean up, or obliterate, the instance and re-install.

  1. Open an elevated command prompt.
  2. Run: %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\resources\app\layout\InstallCleanup.exe -i

This will clean up only instance data such as the installation directory and state. This will make re-installing the instance faster since any workloads and components you had installed would remain cached and would not be re-downloaded.

If you don’t not find InstallCleanup.exe in %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\resources\app\layout – or any directory there above – please download the latest bootstrapper from https://www.visualstudio.com/downloads/ and run it to install. When the workload selection dialog is shown, close the window and run the steps above again.

Update: for up-to-date information, please see https://aka.ms/vs/cleanup.