I am getting below exception when I test my app on a real iPhone device. But the same feature is working fine on android devices and ios simulators.
Unhandled Exception: 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.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/shared/System/Number.Parsing.cs:1781 at System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00016] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/shared/System/Number.Parsing.cs:213 at System.Int32.Parse (System.String s) [0x0000a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Int32.cs:109 at MyProject.eventsHB.get_finalDay () [0x00060] in /Users/pagematics/Projects/MyProject-social-app/MyProject/MyProject/Model/LoginResponse.cs:76 at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395
I have added complete exception details on this file.
My Codes
ViewModel
EventAllItems.Add(eventshb); //The exception is triggering on this line
public Events events;
private ObservableCollection<eventsHB> _eventAllItems;
public ObservableCollection<eventsHB> EventAllItems
{
get
{
return _eventAllItems;
}
set
{
_eventAllItems = value;
OnPropertyChanged("EventAllItems");
}
}
var Response = await client.GetAsync("my rest api path");
if (Response.IsSuccessStatusCode)
{
string response = await Response.Content.ReadAsStringAsync();
events = new Events();
if (response != "")
{
events = JsonConvert.DeserializeObject<Events>(response.ToString());
foreach (var eventshb in events.eventsHB)
{
foreach(var events in eventshb.eventsList)
{
eventshb.eventsListTO = events;
EventAllItems.Add(eventshb); //The exception is triggering on this line
}
lastDateInList = eventshb.day.ToString();
}
}
}
Model Class
public class Events
{
public List<eventsHB> eventsHB { get; set; }
}
public class eventsHB
{
public long day { get; set; }
public List<EventsList> eventsList { get; set; }
public EventsList eventsListTO { get; set; }
}
public class EventsList
{
public string title { get; set; }
public string description { get; set; }
public string longDescription { get; set; }
public string startDate { get; set; }
public string endDate { get; set; }
public string startTime { get; set; }
public string endTime { get; set; }
}
Sample Data:
{
"eventsHB": [
{
"day": 1627914600000,
"eventsList": [
{
"calendarEventId": 236,
"calenderId": 948154,
"title": "Business Meet",
"description": "SD July 2 ED July 5",
"longDescription": "SD July 2 ED July 5"
}
]
},
{
"day": 1628001000000,
"eventsList": [
{
"calendarEventId": 236,
"calenderId": 948154,
"title": "Business Meet",
"description": "SD July 2 ED July 5",
"longDescription": "SD July 2 ED July 5"
}
]
},
{
"day": 1628087400000,
"eventsList": [
{
"calendarEventId": 236,
"calenderId": 948154,
"title": "Business Meet",
"description": "SD July 2 ED July 5",
"longDescription": "SD July 2 ED July 5"
]
}
]
}
Xaml: I am using the eventsListTO
variable to show the details on UI.
<ListView
x:Name="EventsListview"
SeparatorVisibility="None"
ItemsSource="{Binding EventAllItems, Mode=TwoWay}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout
VerticalOptions="CenterAndExpand"
Margin="10,5,10,0"
Orientation="Vertical">
<Frame
VerticalOptions="CenterAndExpand"
HasShadow="False">
<StackLayout
VerticalOptions="CenterAndExpand"
Orientation="Vertical">
<Label
Text="{Binding eventsListTO.title}"
TextColor="#1C7DB4"
HorizontalOptions="Start"
VerticalOptions="Center">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Roboto-Medium" />
<On Platform="Android" Value="Roboto-Medium.ttf#Roboto-Medium" />
<On Platform="UWP" Value="Assets/Fonts/Roboto-Medium.ttf#Roboto" />
</OnPlatform>
</Label.FontFamily>
<Label.FontSize>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Phone>17</OnIdiom.Phone>
<OnIdiom.Tablet>25</OnIdiom.Tablet>
<OnIdiom.Desktop>17</OnIdiom.Desktop>
</OnIdiom>
</Label.FontSize>
</Label>
<Label
Text="{Binding eventsListTO.description}"
TextColor="#1C7DB4"
VerticalTextAlignment="Center"
Margin="0,-3,-5,0"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Roboto-Light" />
<On Platform="Android" Value="Roboto-Light.ttf#Roboto-Light" />
<On Platform="UWP" Value="Assets/Fonts/Roboto-Light.ttf#Roboto" />
</OnPlatform>
</Label.FontFamily>
<Label.FontSize>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Phone>12</OnIdiom.Phone>
<OnIdiom.Tablet>18</OnIdiom.Tablet>
<OnIdiom.Desktop>12</OnIdiom.Desktop>
</OnIdiom>
</Label.FontSize>
</Label>
</StackLayout>
</StackLayout>
</Frame>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<Label/>
</ListView.Footer>
</ListView>
I am listing few items on UI. The exception is showing only on the actual iPhone devices. Everything is working fine on android devices and iPhone simulators.
XF Version: 4.8.0.1821
Mac VS version: 8.10.2
Xcode version: 12.5.1
iPhone versions: 14.6, 14.4
The issue is with the date and time values.
Date issue: On Android devices and ios simulators, the date format is dd/mm/yyyy. But on the actual iPhone device, the date format is dd-mm-yyyy.
Time issue: On ios simulators, we get the AM or PM value of time, but on the actual iPhone device the time is in 24-hour format without AM or PM.