CompositionContractMismatchException in VS 2015 Extension implementing ITeamExplorerSection - c#

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.

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.

Related

View the body of an assembly file(.NET 5) [duplicate]

I know that I can set up Visual Studio to debug through the .NET framework source code.
But is there a way that I can browse the code while NOT debugging - i.e., being able to press F12 or "Go to definition"?
I thought that if that feature isn't built into Visual Studio then there may be a plug-in that might add it?
There is a very new feature in Visual Studio 2017 version 15.6
You can see decompiled source code without any plugin! Btw, Ref12 doesn't work for VS2017.
Tools > Options , expand Text Editor > C# > Advanced, and enable "Enable navigation to decompiled sources (experimental)".
Ref: https://learn.microsoft.com/en-us/visualstudio/ide/go-to-and-peek-definition?view=vs-2017#view-decompiled-source-definitions-instead-of-metadata-c
With ReSharper it's possible to browse .NET sources by enabling ReSharper -> Options -> Tools -> External Sources -> Navigation to Sources.
After enabling this option new menu item "Navigate To -> Decompiled Sources" appears by right click on type/method/whatever.
Navigation also works with F12 for me.
I just discovered this extension that pretty much addresses my problem. The only thing is that it opens the source in the browser rather than in Visual Studio, but it's no big deal because even in the browser you can click the source code to navigate to types etc.
It was presented on Scott Hanselman's blog a couple of days ago:
Community member and fabulous coder Schabse Laks has created a Visual Studio extension for VS2010, 2012, and 2013! This extension sends calls to Go To Definition (or pressing F12 on a symbol) directly to the code online (when it's .NET Framework code, not yours).
You can download this companion "Ref12" Visual Studio Extension now! Just Goto Definition on any .NET type we have source for and it'll launch your default browser so you can explore the .NET Framework source yourself! Thanks Schabse!
Update:
As per the comments, for VS 2022 and .NET Core, use this fork of the extension: https://marketplace.visualstudio.com/items?itemName=EfreyKong.Ref12-VS2022
I downloaded the .NET Framework source code from here http://referencesource.microsoft.com/netframework.aspx.
Since I am working with .NET 4.0, I chose ".Net/4" from the list. (What is ".NET/8.0" in that list? No idea.)
I wrote some scripts to rearrange the bloody mess they give us:
Into a reasonable hierarchy of directories;
To remove duplicated code (why is every file doubled, or was my install bad?);
Rename all top-level namespaces to not conflict with native ones baked into Intellisense.
Example: System.Windows.Controls -> xSystem.Windows.Controls
Then follow these steps:
Create a new Visual Studio project of type "Class Library"
Remove all references -- yes, even the system ones.
Drag/drop all of your massaged .NET code into the root of your project.
Wait about 30 minutes for VS processing. VS will appear to freeze; be patient.
Intellisense/ReSharper still complains about heaps of problems, but now I can right click and select "Go to Declaration/Implementation".
Visual Studio is about 600MB with this project loaded.
I am using Visual Studio 2013 Ultimate.
1. Choose menu: TOOLS \ Extensions and Updates...
2. Choose Visual Studio Gallery \ Search Results. Search term: Ref12.
3. Download then install.
4. Restart Visual Studio.
5. Try: Click mouse on Class or method, press F12 and see result at http://referencesource.microsoft.com/
I've never tried this but supposedly the code is publicly available:
[Edit]
http://referencesource.microsoft.com/
There is the .NET Mass Downloader, but I think the straightforward answer to your question is, no.
However I now see Microsoft has made the code more easily downloadable.
Nevertheless note that even for your own code, when not debugging, unless you have the project open, VS does not help you locate source code (even though when you find it yourself break points will work when you start debugging again, if the .pdb files correspond).

C# TFS Set Latest Information of File programmatically?

I wrote an Visual Studio Extension for our Company, which gets the Specific Version of Files in a Solution based on Microsoft TFS. We use Visual Studio 2015 / 2019.
My question is, is there some way to set the "Latest" Information of an File which gets displayed in the Source Control Explorer programmatically?
Like this:
Latest Information Visual Studio
So i have a list with all files which i want to get.
Before i used this method to get for every file:
WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(filePath);
Workspace ws = workspaceInfo.GetWorkspace(new TfsTeamProjectCollection(workspaceInfo.ServerUri));
status = ws.Get(new GetRequest(new ItemSpec(filePath, RecursionType.Full), VersionSpec.Latest), GetOptions.GetAll);
This worked fine and refreshed the latest information.
Sadly this method is to slow compared to the "real" Get Specific Version from Visual Studio.
Now I tried this method, which is much faster, but doesn´t change the latest information of the file:
item.DownloadFile(filePath);
Even if I downloaded the file (I checked the differences between changesets) and got the latest version of it, the information in Source Control Explorer keeps saying "No".
Does someone know a solution for this, or even a better solution?
Why you don't use the VersionControlServer.DownloadFile instead the item.downloadfile? https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/bb138622(v%3Dvs.110)

Microsoft.Build.Utilities.ToolLocationHelper::GetPathToStandardLibraries(MonoAndroid) - How to solve this?

After installing Visual Studio 2017 version 15.6. Preview, I'm not able to create Cross Platform project. Every single time, I'm getting error from the picture. Any solution for this?
It's actually a bug of Xamarin Visual Studio Template, see bugzilla 60995, a temporary workaround is provided for this bug:
Workaround:
Apparently when the template is generated it'll add the following line in the android csproj file:
<TargetFrameworkVersion>"v8.0"</TargetFrameworkVersion>
The solution then is to change it to:
<TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
Without the quotes and after that, everything works fine again!

Visual Studio 2015: error building solution

I have a .Net C# solution that can be built in Visual Studio 2013 without any problem. It reference several dll's, one of them done it by me.
The problem starts when I have tried to build it in Visual Studio 2015, without doing any change (is exactly the same soultion and code). The next error (between 600 more because of this one) is shown:
Error metada file *.dll could not be open: invalid public key
I have searched a lot, but I can not find a solution for it. I would appreciate any help.
**** EDITED WITH MORE INFO ****
I use ConfuserEX. If I use the dll before ofuscate it, it works. The dll is not signed, so ofuscate it should not be a problem. Any ideas? (I have to ofuscate it and it have works for a long time and still works with VS2013)
Old question, but for those that look here, the issue is documented as ConfuserEx issue #450:
https://github.com/yck1509/ConfuserEx/issues/450
A fix was added to the follow-on project neo-ConfuserEx, but has not been published in a release of the project (as of this writing).
https://github.com/XenocodeRCE/neo-ConfuserEx
The description of the fix is: Fix issue yck1509#450 for VS2015 and VS2017 build error when resource protection enabled (BUG: "CS0009 ... -- Invalid public key."). Which suggests you can turn off resource protection as a work-around.

Issues with intellisense, references, and builds in Visual Studio 2008

Hoping you can help me -- the strangest thing seems to have happened with my VS install.
System config: Windows 7 Pro x64, Visual Studio 2008 SP1, C#, ASP.NET 3.5.
I have two web site projects in a solution. I am referencing NUnit / NHibernate (did this by right-clicking on the project and selecting "Add Reference". I've done this for several projects in the past).
Things were working fine but recently stopped working and I can't figure out why. Intellisense completely disappears for any files in my App_Code directory, and none of the references are recognized (they are recognized by any file in the root directory of the web site project.
Additionally, pretty simple commands like the following (in Page_Load) fail (assume TextBox1 is definitely an element on the page):
if (Page.IsPostBack)
{
str test1;
test1 = TextBox1.Text;
}
It says that all the page elements are null or that it can't access them.
At first I thought it was me, but due to the combination of issues, it seems to be Visual Studio itself.
I've tried clearing the temp directories & rebuilding the solution. I've also tried tools --> options --> text editor settings to ensure intellisense is turned on.
I'd appreciate any help you can give!
If you think it is VS then try running it with this command line to get it back to factory defaults: devenv /resetsettings
Alternatively you may be experiencing issues due to the fact that intellisense only works on code that is (pre)compiled check the following:
a required folder is marked as excluded,
there is an issue compiling a referenced project.
compile error in the global.asax class. Note: extra { or } in a class bubbles from the root folder, usually kills intellisense. (Clean solution then build watch output for error's)

Categories