8000 CompositionContractMismatchException when I open GitHubVS.sln directly · Issue #976 · github/VisualStudio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

CompositionContractMismatchException when I open GitHubVS.sln directly #976

Closed
jcansdale opened this issue May 4, 2017 · 1 comment
Closed
Assignees
Labels

Comments

@jcansdale
Copy link
Collaborator
  • GitHub Extension for Visual Studio version: 2.2.1.0 (experimental)
  • Visual Studio version: 2015

What happened (with steps, logs and screenshots, if possible)

I opened the GitHubVS.sln and started experiencing random exceptions similar to this:

System.ComponentModel.Composition.CompositionContractMismatchException:
    Cannot cast the underlying exported value of type
    'Microsoft.VisualStudio.Composition.NetFxAdapters+MefV1ExportProvider+
      ComposablePartForExportFactory' to type 'Microsoft.TeamFoundation.Controls.ITeamExplorerSection'.
   at System.ComponentModel.Composition.ExportServices.CastExportedValue[T](ICompositionElement element, Object exportedValue)
   at System.ComponentModel.Composition.ReflectionModel.ExportFactoryCreator.LifetimeContext.GetExportLifetimeContextFromExport[T](Export export)
   at System.ComponentModel.Composition.ReflectionModel.ExportFactoryCreator.<>c__DisplayClass6_0`2.<CreateStronglyTypedExportFactoryOfTM>b__0()
   at System.ComponentModel.Composition.ExportFactory`1.CreateExport()
   at Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.Framework.TeamExplorerSectionHost.Create()
@jcansdale jcansdale added the bug label May 4, 2017
@jcansdale jcansdale self-assigned this May 4, 2017
@jcansdale
Copy link
Collaborator Author
jcansdale commented May 4, 2017

This is a strange and tricky to track down issue that is caused by dependencies from the opened solution being loaded into Visual Studio! It only seems to happen when Visual Studio is launched by opening a .sln file. The problem assemblies are copied to and loaded from the following location: %LOCALAPPDATA%\Microsoft\VisualStudio\14.0\ProjectAssemblies.

The fix is to ensure that any required assembly resolution is done before Visual Studio's project system has a chance to mess things up. The TryAddPriorityAssemblyResolve method is what does this.
https://github.com/github/VisualStudio/pull/970/files#diff-12f933fbcb54af34ee67452d94924a4eR52

I accidentally disabled this method while refactoring and started seeing these exceptions again. I thought it would be a good idea to capture it here in case it ever starts happening again!

See also #923, #970.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0