Search code examples
c#visual-studio-2015vs-extensibility

CompositionContractMismatchException in VS 2015 Extension implementing ITeamExplorerSection


I'm trying to update my Visual Studio Extension Diff All Files to support Visual Studio 2015. Everything works fine in VS 2012 and 2013, but in 2015 it throws the following error when I open the Team Explorer Pending Changes Windows, which should show my new control on it:

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__DisplayClass4`2.<CreateStronglyTypedExportFactoryOfTM>b__5()
   at System.ComponentModel.Composition.ExportFactory`1.CreateExport()
   at Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.Framework.TeamExplorerSectionHost.Create()

This blog post explains that VS 2015 moved from MEF v1 to v2, which I think may be part of the problem, but I'm not really sure. I'm fairly certain that the error occurs when it tries to process the following attribute on my VSPackage control class:

[TeamExplorerSection(PendingChangesSection.SectionId, TeamExplorerPageIds.PendingChanges, 35)]

Any ideas what the problem might be or how to solve it?

The project is open source so you can download it and reproduce the problem if you like. You can grab the source code from here, just make sure you get the "AddVs2015Support" branch.

Thanks in advance.


Solution

  • So it turns out that I had included the 2015 (v14.0) TFS assemblies in the VS 2015 project, but in their reference properties Specific Version was set to False. I flipped that to True for the TFS assembly references and it's working as expected now.

    I had also posted this question in the MSDN Forums and they were able to point me in the right direction.