I am currently having a problem building my Xamarin.Forms solution. I\'m getting an error of The \"XamlCTask\" task failed unexpectedly
. I tried looking at the
This error indicates that the versions of the NuGet packages and the version of Xamarin.Forms do not match. Just update the NuGet packages in the project or remove Xamarin.Forms from the package list, then add it again.
Hope could be usefull to someone else, I had the same error shown in the question (..."XamlCTask" task failed unexpectedly. System.ArgumentException: An item with the same key has already been added...), my issue was caused by a ListViewTemplate, which contained a DataTemplate, in which I putted two elements, a Label and a Picker.
Grouping Label e Picker in a unique element, a Frame, inside the DataTemplate, solved my issue.
I already resolved the issue. Since I was renaming the namespaces, i named the namespaces alias wrong. I used dots (.) in the alias name like this xmlns:sample.pages="clr-namespace:JustAnotherNamespace"
. When I removed the dots, the solution was able to build!
This occurs sometimes if your Xamarin Forms nugets are going corrupt. Uninstall and reinstall them.
I had 35 pages in my app with an assembly reference to turn on/off xaml compilation. To find the offending page I had to remove the assembly reference and place the following on each page and rebuild the shared project one at a time until I found the offending page (make sure you have release build selected).
#if (DEBUG != true)
[XamlCompilation(XamlCompilationOptions.Compile)]
#endif
Once you find the page, it's most likely a xaml issue like so many solutions above. For me it was because I had accidentally placed 2 resource dictionaries on the page so it was easy to spot, your's may not be so easy.
First of all this issue will be raised when xamarin.forms version is not compatible with the nuget that you are pointed to. So i'd like to tell you these steps and go ahead.
Step1: Update Xamarin.Forms version in PCL and all other projects.
Step2: Check for matching dependencies with nuget package.i.e make sure everywhere the the solution is using the **same** version of the Xamarin.Forms.
Hope this will helps you.