Archive for the ‘Visual Studio 2010’ Category

Unknown build error, ‘An item with the same key has already been added.’

with 2 comments

I got this error today when trying to build a C# solution today.
In my case the error was caused by the fact that I had the same file added twice in the .csproj file. (This happened after a merge in the *.csproj file).
To find the exact file would have been very hard since there can be thousands of files in a *.csproj.
The first thing to do is to find the exact project which is causing the issue. Visual studio is using msbuild in the background to do the builds, but it’s outputing very little information from msbuild.
This can be controlled by going to Tools->Options->Projects and Solutions->Build and Run. Set MSBuild project output verbosity to Diagnostic.
Now do a build again. After it fails display the output window. Debug->Windows->Output. Select “Show output from” -> Build. Find the first “Build failed” text.
Now you know which project’s build failed.
Go to Build->Clean, then right click on the specific project that is causing the problem and select build. (Do not build entire solution).
If you do that instead of building the entire solution, you will sometimes get an error with the exact file which is causing the build problem.
If it still doesn’t show you the file, you will have to go through the csproj and find out which line is duplicate.
Now unload that project (right click -> unload). Right click the unloaded project -> edit. Now search for that file which is causing the build problem and ensure that it is only added once in the csproj.
E.g. if the file is called EquipmentDetailsTitleBarPopup.xaml, look for duplicates of

    <Page Include="Features\Equipments\EquipmentDetailsTitleBarPopup.xaml">

and remove one of them.
Now reload the project (right click -> reload) and build again.

This fixed it for me.


Written by Liviu Trifoi

January 18, 2013 at 1:35 pm

Posted in .NET, C#, Visual Studio 2010

Unable to determine the URL to the Xap file from web

leave a comment »

I encountered today this undocumented error: “Unable to determine the URL to the Xap file from web XXX”, after renaming one of my silverlight 4 projects, which was set to run Out of Browser.
Supposing you renamed your project from XXX to YYY.
To fix the error above, go to your YYY.csproj.user on the disk, and open it for editing with notepad.
Then change


Now save it, and you’re good to go.

Usually *.csproj.user files should not be under source control.
So if you rename a silverlight project which a colleague of yours has set it to be ran out of browser on his computer, then he will get this error unless you share the same *.csproj.user on the source control (which is not a good idea).

I think a visual studio 2010 improvement is needed here, that describes the situation better. Something like: “Unable to determine the URL to the Xap file from web XXX. If the project was renamed, please rename it inside your *.csproj.user” file settings as well”

Written by Liviu Trifoi

June 1, 2011 at 8:48 am