1

I have Xamarin.Forms application, which is running fine on Android but while trying to test it on iOS, I am facing runtime exception. Stacktrace is mentioned below.

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
List`1[T].get_Item (System.Int32 index) /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:161
OrderedDictionary`2[TKey,TValue].get_Item (System.Int32 index) D:\a\1\s\Xamarin.Forms.Core\OrderedDictionary.cs:100
TemplatedItemsList`2[TView,TItem].GetGroup (System.Int32 index) D:\a\1\s\Xamarin.Forms.Core\TemplatedItemsList.cs:569
ITemplatedItemsList<TItem>.GetGroup (System.Int32 index) D:\a\1\s\Xamarin.Forms.Core\TemplatedItemsList.cs:574
ListViewRenderer+UnevenListViewDataSource.GetEstimatedRowHeight (UIKit.UITableView table) D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:799
ListViewRenderer+UnevenListViewDataSource.UpdateEstimatedRowHeight (UIKit.UITableView tableView) D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:830
ListViewRenderer+ListViewDataSource.DetermineEstimatedRowHeight () D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:1281
FormsUITableViewController.ViewWillLayoutSubviews () D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:1609
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) /Library/Frameworks/Xamarin.iOS.framework/Versions/13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:86
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) /Library/Frameworks/Xamarin.iOS.framework/Versions/13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:65
Application.Main (System.String[] args) ...../[ProjectName].iOS/Main.cs:20

I am using

Xamarin.Forms version 4.5.0.617 Xamarin.iOS version 13.16.0.13

UPDATE

Main.cs: 20 UIApplication.Main(args, null, "AppDelegate");

Jay Bhiyani
  • 313
  • 1
  • 4
  • 14
  • I think that you need to look at the List View that you are trying to display. It appears that there is an issue either with data or with how it is displayed. Either the data or the some style is missing for iOS that is present for Android. – ChrisBD May 05 '20 at 10:03
  • I have many other List Views in the same XAML file, but issue is with only one List View. The data is fine, there are no issues with data – Jay Bhiyani May 05 '20 at 10:30
  • You're not giving us much to go on. What is called at Line 20 of main.cs and do you have a parameter called `index` perhaps used to set a selected list item? – ChrisBD May 05 '20 at 10:55
  • I have updated the quetion with line:20 I do not have any parameter called ```index```. – Jay Bhiyani May 05 '20 at 10:59
  • Ah I see, the start line in the iOS section of the project, so the issue is triggered within `public App()` of the common project. I take it from your comment that you open up a View and that triggers this exception? If you're certain that the data is okay, are there any resources that might not be e.g. text or image resources ? – ChrisBD May 05 '20 at 11:12
  • Yes, while opening a view, the exception is thrown. If I remove ```ItemsSource``` property of ```ListVIew``` tag in XAML file, it works fine. I am not getting any clue why it is behaving like this!! – Jay Bhiyani May 05 '20 at 11:38
  • Xamarin will cope if the `ItemSource` is null, I think that there may be an issue in your `ListView.ItemTemplate`, unless you have references to a resource e.g. language strings in your ItemSource objects. – ChrisBD May 05 '20 at 12:18

0 Answers0