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
disable XamlC
on the failing Page
[XamlCompilationAttribute (XamlCompilationOptions.Skip)]
public partial class MyPageThrowing {}
or at the Assembly level
[assembly:XamlCompilationAttribute (XamlCompilationOptions.Skip)]
An issue throwing the same exception and the same StackTrace had been fixed in the next (to date) version of xamarin.forms which should be 2.3.3-pre3 or 2.3.4.
The only way to know for sure would be to paste your failing Xaml page here, or even better, on http://bugzilla.xamarin.com.
I really encourage you to do so. If the issue is not fixed already. Either it's an issue in your Xaml and this needs a better exception being thrown, or it's an unsupported case in XamlC, and this require a fix.
I had this error too. In my case it turned out to be a xaml issue. I hadn't made any recent changes to any dlls or references. I had just made some recent xaml changes and I suddenly started getting this error. This xaml I wrote had caused the issue:
<StackLayout Grid.Row="4" Orientation="Horizontal" HorizontalOptions="Center" >
<StackLayout.Children>
<Label Text="Holes" BackgroundColor="White" VerticalOptions="Center"/>
<Entry x:Name="entryHoles" BackgroundColor="White" WidthRequest="100"/>
</StackLayout.Children>
<StackLayout.Children>
<Label Text="Par" BackgroundColor="White" VerticalOptions="Center"/>
<Entry x:Name="entryPar" BackgroundColor="White" WidthRequest="100"/>
</StackLayout.Children>
</StackLayout>
There should be only one StackLayout.Children tag. This is what I switched to to get this error to go away:
<StackLayout Grid.Row="4" Orientation="Horizontal" HorizontalOptions="Center" >
<StackLayout.Children>
<Label Text="Holes" BackgroundColor="White" VerticalOptions="Center"/>
<Entry x:Name="entryHoles" BackgroundColor="White" WidthRequest="100"/>
<Label Text="Par" BackgroundColor="White" VerticalOptions="Center"/>
<Entry x:Name="entryPar" BackgroundColor="White" WidthRequest="100"/>
</StackLayout.Children>
</StackLayout>
I'll bet the extra StackLayout.Children tag caused this message: "An item with the same key has already been added." If so, it would have been great if Microsoft could have told us exactly what the duplicate item was. I wasted all kinds of time updating NuGet packages.
I had the same problem. Clean or restart didn't help. Now I tried the simulator instead of the device. This worked. Afterwards I was able to build and run on the device.
Edit:
Now I had the issue a second time. But here it was different. The app didn't compile anymore. Now it seems to work. This is what I've done:
in this case removing bin and obj folder it seems works like a charm!
Perhaps you have 2 instances of Visual Studio accessing the same device.