The “XamlCTask” task failed unexpectedly in Xamarin

前端 未结 11 1939
孤街浪徒
孤街浪徒 2021-01-12 13:59

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

相关标签:
11条回答
  • 2021-01-12 14:32

    tl;dr:

    disable XamlC on the failing Page

    [XamlCompilationAttribute (XamlCompilationOptions.Skip)]
    public partial class MyPageThrowing {}
    

    or at the Assembly level

    [assembly:XamlCompilationAttribute (XamlCompilationOptions.Skip)]
    

    Long Story

    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.

    0 讨论(0)
  • 2021-01-12 14:39

    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.

    0 讨论(0)
  • 2021-01-12 14:40

    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:

    • Upgrade to XF 2.3.3.168
    • Upgrade to XF 2.3.3.168 for the referenced project
    • Fixed a compile error (only appeared after update)
    0 讨论(0)
  • 2021-01-12 14:42

    in this case removing bin and obj folder it seems works like a charm!

    0 讨论(0)
  • 2021-01-12 14:43

    Perhaps you have 2 instances of Visual Studio accessing the same device.

    0 讨论(0)
提交回复
热议问题