Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

The application is in break mode - "Specified cast is not valid"

$
0
0

When developing in Xamarin Forms if I will make a mistake in XAML syntax, I receive an error like this: "The application is in break mode. Unhandled exception: Specified cast is not valid"

Here is an example how to produce such an error:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Test.Views.ItemsPage"
              Title="{Binding Title}"
             x:Name="BrowseItemsPage">
    <ContentPage.Content>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <ListView Padding="0,30,0,0" Grid.Row="0" x:Name="ItemsListView" 
                ItemsSource="{Binding Items}"
                VerticalOptions="FillAndExpand"
                 HasUnevenRows="true">
                <ListView.Header>
                    <Label Text="Unread messages: 3"/>
                </ListView.Header>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <!--<ViewCell>-->
                            <StackLayout Padding="10">
                                <Label Text="{Binding Text}" 
                       LineBreakMode="NoWrap" 
                       Style="{DynamicResource ListItemTextStyle}" 
                       FontSize="16" />
                                <Label Text="{Binding Description}" 
                       LineBreakMode="NoWrap"
                       Style="{DynamicResource ListItemDetailTextStyle}"
                       FontSize="13" />
                            </StackLayout>
                        <!--</ViewCell>-->
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </ContentPage.Content>
</ContentPage>

As you can see, I have just commented out ViewCell tags. In practice, this error happens very often when you will break something in XAML syntax and the exception tells completely nothing. Is there a way to catch this exception and see details. Because when I have some complicated XAML it takes some time to detect which change in code produced that exception. I would be grateful for any help :smile:


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>