-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Corrupt extension cache and missing MEF exports #1859
Description
- GitHub Extension for Visual Studio version: 2.5.4.3349 (probably any)
- Visual Studio version: 15.6.6, 15.7.5, 15.7.3, 15.7.5, 15.7.5, 15.7.6, 5.8 Preview 5, 5.8 Preview 4
We have been seeing many issues that involve missing MEF components, for example:
- GitHub Extension broken with VS 15.7.6 #1826 GitHub Extension broken with VS 15.7.6
- SetSite failed for the package [GitHubPackage], VS 15.8 Preview 4/5 #1810 SetSite failed for the package [GitHubPackage], VS 15.8 Preview 4/5
- Error On Project Load #1812 Error On Project Load
Symptoms
These tend to manifest themselves as follows on the GitHub pane:
System.InvalidOperationException: Could not locate any instances of contract GitHub.Services.ITeamExplorerServiceHolder.
at GitHub.VisualStudio.GitHubServiceProvider.GetService(Type serviceType) in C:\projects\visualstudio\src\GitHub.VisualStudio\Services\GitHubServiceProvider.cs:line 147
at GitHub.VisualStudio.GitHubServiceProvider.GetService[T]() in C:\projects\visualstudio\src\GitHub.VisualStudio\Services\GitHubServiceProvider.cs:line 153
at GitHub.VisualStudio.UI.GitHubPane.<InitializeAsync>d__12.MoveNext() in C:\projects\visualstudio\src\GitHub.VisualStudio\UI\GitHubPane.cs:line 98
Or like this when opening a solution that's hosted on GitHub:
With an entry in the ActivityLog:
<description>
SetSite failed for package [GitHubPackage]
Source: 'System.ComponentModel.Composition'
Description: No exports were found that match the constraint:
ContractName=GitHub.Commands.IOpenFromUrlCommand
RequiredTypeIdentity=GitHub.Commands.IOpenFromUrlCommand
</description>What's going on
Update from Daniel Griffen @dgriffen on Gitter.
@jcansdale I was able to reproduce this locally! I've figured out the issue and am working on how to fix it on our end or provide you with a workaround.
@jcansdale there is a slight issue where the target version is getting the incorrect version of the running VS process and therefore excluding both your teamfoundation mef assets.
The commit that added that to your extension was here: c9703cd#diff-f5cce9abffe08468ca7c1c1cd08cc17f
@jcansdale the bug is that sometimes servicehub's version is used which is not tied directly to the VS version (currently, its ~1.3 I think).
This doesn't appear to be caused by a specific version of GitHub for Visual Studio or MEF component, but seems to be a random corruption of the extension cache see above.
Simply clearing the MEF component cache or running devenv.exe /updateConfiguration won't repair the extension cache (which is usually what resolves missing MEF components).
How to fix
Clearing the extension and MEF caches
The quickest way is to delete the following file and directory (where 15.0_xxxxxxxx corresponds to a particular instance of Visual Studio):
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\15.0_xxxxxxxx\Extensions\extensions.en-US.cache
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\15.0_xxxxxxxx\ComponentModelCache
Deleting extensions.en-US.cache causes the extension cache to be recreated and deleting the ComponentModelCache directory clears the MEF component cache.
Reinstalling the extension
The alternative way is to uninstall and then re-install GitHub for Visual Studio.
This can be error prone when done manually because the VSIX Installer often appears behind other windows. It's easy to think the uninstall has completed when it hasn't even started. Perhaps we could provide a script for doing this?
Automatic detection
Missing MEF components would be easy to detect during our package initialization. The package did not load correctly dialog only appears because we don't handle an exception in our package initialization. At the very least we could point users to instructions on how to repair their extension cache.
Automatic repair
It's easier to find the relevant cache files from inside an instance of Visual Studio that it is to find the correct instance-Guid and paths from an external script. It would be straightforward to detect suspected cache corruption and offer to perform an automatic repair.
