Xaml page throwing System.FormatException

Anil.ApexAnil.Apex USMember ✭✭
edited September 2016 in Xamarin.Forms

2 Xaml pages in my app are throwing System.FormatException: : Input string was not in a correct format.

It's showing String to Number parsing error. I've checked my Xaml pages & haven't found any alphanumeric characters in place of a number.

Xaml Page:

    <?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="FavQuotes.Views.QuoterGroupPage"
             xmlns:local="clr-namespace:FavQuotes.Views;assembly=FavQuotes"
             xmlns:rating="clr-namespace:Syncfusion.SfRating.XForms;assembly=Syncfusion.SfRating.XForms"
             xmlns:behavior="clr-namespace:Behaviors;assembly=Behaviors"
             BindingContext="{Binding Source={StaticResource VmLocator},Path=QuoterGroupPageVm}" Title="Quoter's Group">
  <ContentPage.Padding>
    <OnPlatform x:TypeArguments="Thickness" Android="5,0" WinPhone="8,0" iOS="5,20,5,0"/>
  </ContentPage.Padding>

  <ContentPage.Resources>
    <ResourceDictionary>
      <local:QuoteDetailsPage x:Key="QuoteDetailsDestinationPage"/>
    </ResourceDictionary>
  </ContentPage.Resources>

  <ListView ItemsSource="{Binding QuoterGroup}" SelectedItem="{Binding SelectedQuote, Mode=OneWayToSource}"
            IsGroupingEnabled="True" GroupDisplayBinding="{Binding Key.Name}"
            HasUnevenRows="True">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <StackLayout Orientation="Horizontal" Spacing="60">
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition Height="40"/>
                <RowDefinition Height="Auto"/>
              </Grid.RowDefinitions>

              <Label Text="{Binding Statement}"/>
              <Label Grid.Row="1" Text="{Binding Category.Name}" FontSize="8" BackgroundColor="Aqua"/>
            </Grid>

            <rating:SfRating ItemCount="1" Precision="Exact"
                             Value="{Binding Favorite, Mode=TwoWay, Converter={StaticResource RatingConverter}}"
                             HorizontalOptions="End" VerticalOptions="Start">

              <rating:SfRating.RatingSettings>
                <rating:SfRatingSettings RatedFill="Yellow"/>
              </rating:SfRating.RatingSettings>

              <rating:SfRating.Behaviors>
                <behavior:EventHandlerBehavior EventName="ValueChanged">
                  <behavior:InvokeCommandAction Command="{Binding Source={StaticResource VmLocator},Path=QuoterGroupPageVm.MarkQuoteFavorite}"
                                                CommandParameter="{Binding}"/>
                </behavior:EventHandlerBehavior>
              </rating:SfRating.Behaviors>

            </rating:SfRating>
          </StackLayout>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>

    <ListView.Behaviors>
      <behavior:EventHandlerBehavior EventName="ItemSelected">
        <behavior:InvokeCommandAction Command="{Binding NavigateToQuoteDetail}" CommandParameter="{Binding Source={StaticResource QuoteDetailsDestinationPage}}"/>
      </behavior:EventHandlerBehavior>
    </ListView.Behaviors>
  </ListView>

  <ContentPage.Behaviors>
    <behavior:EventHandlerBehavior EventName="Appearing">
      <behavior:InvokeCommandAction Command="{Binding GetQuoterGroup}"/>
    </behavior:EventHandlerBehavior>
  </ContentPage.Behaviors>

</ContentPage>  

Exception Message:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo(Object value, Type toType, Func`1 getConverter, IServic

StackTrace:

       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
   at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.XamlLoader.Visit(RootNode rootnode, HydratationContext visitorContext)
   at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, String xaml)
   at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml](TXaml view, Type callingType)
   at FavQuotes.Views.QuoterGroupPage.InitializeComponent()
   at FavQuotes.Views.QuoterGroupPage..ctor()
   at FavQuotes.App..ctor()
   at FavQuotes.UWP.MainPage..ctor()
   at FavQuotes.UWP.FavQuotes_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_4_MainPage()
   at FavQuotes.UWP.FavQuotes_UWP_XamlTypeInfo.XamlUserType.ActivateInstance()
   at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
   at FavQuotes.UWP.App.OnLaunched(LaunchActivatedEventArgs e)

InnerException Message:

Input string was not in a correct format.

InnerException StackTrace:

       at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo(Object value, Type toType, Func`1 getConverter, IServiceProvider serviceProvider)
   at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo(Object value, Type toType, Func`1 minfoRetriever, IServiceProvider serviceProvider)
   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydratationContext context, IXmlLineInfo lineInfo)
   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit(ValueNode node, INode parentNode)
   at Xamarin.Forms.Xaml.ValueNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.XamlLoader.Visit(RootNode rootnode, HydratationContext visitorContext)
   at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, String xaml)
   at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml](TXaml view, Type callingType)
   at FavQuotes.Views.QuoteDetailsPage.InitializeComponent()
   at FavQuotes.Views.QuoteDetailsPage..ctor()

Another Xaml Page: (with same System.FormatException)

    <?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="FavQuotes.Views.FavoritesPage" Title="Favorites"
             xmlns:local="clr-namespace:FavQuotes.Views;assembly=FavQuotes"
             xmlns:rating="clr-namespace:Syncfusion.SfRating.XForms;assembly=Syncfusion.SfRating.XForms"
             xmlns:behaviors="clr-namespace:Behaviors;assembly=Behaviors"
             BindingContext="{Binding Source={StaticResource VmLocator}, Path=FavoritesPageVm}">

  <ContentPage.Padding>
    <OnPlatform x:TypeArguments="Thickness" Android="5,0" WinPhone="8,0" iOS="5,20,5,0"/>
  </ContentPage.Padding>

  <ContentPage.Resources>
    <ResourceDictionary>
      <local:QuoteDetailsPage x:Key="QuoteDetailsDestinationPage"/>
    </ResourceDictionary>
  </ContentPage.Resources>

  <ListView ItemsSource="{Binding Quotes}" SelectedItem="{Binding SelectedQuote, Mode=OneWayToSource}" HasUnevenRows="True">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition/>
              <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Label Text="{Binding Statement}" FontSize="15"/>
            <rating:SfRating Grid.Column="1" Grid.RowSpan="2" ItemCount="1" Precision="Exact" ItemSize="40"
                             Value="{Binding Favorite, Mode=TwoWay, Converter={StaticResource RatingConverter}}"
                             HorizontalOptions="End" VerticalOptions="Start" Margin="50,5,5,10">

                <rating:SfRating.RatingSettings>
                <rating:SfRatingSettings RatedFill="Yellow" RatedStroke="Black"/>
              </rating:SfRating.RatingSettings>

              <rating:SfRating.Behaviors>
                <behaviors:EventHandlerBehavior EventName="ValueChanged">
                  <behaviors:InvokeCommandAction Command="{Binding Source={StaticResource VmLocator}, Path=FavoritesPageVm.MarkFavorite}"/>
                </behaviors:EventHandlerBehavior>
              </rating:SfRating.Behaviors>

            </rating:SfRating>

            <Label Grid.Row="1" Text="{Binding Quoter.Name}" FontSize="9" BackgroundColor="Aqua"/>
            <Label Grid.Row="1" Grid.Column="1" Text="{Binding Category.Name}" FontSize="9" BackgroundColor="Aqua"/>

          </Grid>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>

    <ListView.Behaviors>
      <behaviors:EventHandlerBehavior EventName="ItemSelected">
        <behaviors:InvokeCommandAction Command="{Binding ShowQuoteDetail}" 
                                       CommandParameter="{StaticResource QuoteDetailsDestinationPage}"/>
      </behaviors:EventHandlerBehavior>
    </ListView.Behaviors>

  </ListView>

  <ContentPage.Behaviors>
    <behaviors:EventHandlerBehavior EventName="Appearing">
      <behaviors:InvokeCommandAction Command="{Binding ReadFavorites}"/>
    </behaviors:EventHandlerBehavior>
  </ContentPage.Behaviors>

</ContentPage>

Best Answer

Answers

  • HunumanHunuman GBMember ✭✭✭✭
    edited September 2016

    Hi @Anil.Apex

    This question, like so many on here are really a cry of "I don't know how to debug this!".

    Every developer must be able to debug, or they are not a developer.

    To paraphrase the proverb:
    Debug a man's code and you help him for a day;
    Teach a man to debug and you help him for a lifetime.

    So I am not going to debug such issues , but I will explain how you can approach debugging it:
    The way to start debugging these types of XAML issues is to:

    1. Comment out a individual section of the XAML, making sure that you don't introduce new errors.
    2. Build and test.
    3. If the error is still there, uncomment the area you just commented out, and start again with step 1.
    4. If the error disappears, then you know the error is in the area you last commented out.

    Repeat these steps as needed, until you find the location of the issue, which should allow you to debug further into the problem.

    For a introduction to debugging please see:
    Video - Debugging 101 in Visual Studio

    Hope this points you in the right direction,

    Tim

  • HunumanHunuman GBMember ✭✭✭✭

    Hi @Anil.Apex

    I am glad your bug is sorted, and I agree the IDE's communication of XAML errors leaves a lot to be desired.

    Have a good one,

    Tim

Sign In or Register to comment.