Bug 59489 - InvalidOperationException within ListViewRenderer's TemplatedItems
Summary: InvalidOperationException within ListViewRenderer's TemplatedItems
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.5
Hardware: PC Windows
: High critical
Target Milestone: 2.4.0
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-14 12:10 UTC by Mathias Hartner
Modified: 2017-09-16 14:44 UTC (History)
4 users (show)

Tags: ac fr
Is this bug a regression?: Yes
Last known good build: 2.3.5.239-pre3

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Mathias Hartner 2017-09-14 12:10:20 UTC
Hey guys,

I encountered following exception while list view items are getting updated cyclically (every second):

2017-09-14 11:42:01.534 [1] [Error] An unhandled exception occurred and was caught by global exception handler TaskSchedulerOnUnobservedTaskException. System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
  at Xamarin.Forms.ListProxy+ProxyEnumerator.MoveNext () [0x00013] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:418 
  at Xamarin.Forms.Internals.TemplatedItemsList`2+<GetEnumerator>d__79[TView,TItem].MoveNext () [0x00085] in <937957814f5d45be82b66795cb584841>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.<CacheDefinedRowHeights>b__6_0 () [0x0007f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:643 
  at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.20/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2879 
  at System.Threading.Tasks.Task.Execute () [0x00010] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.20/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502 
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.InvalidOperationException: Operation is not valid due to the current state of the object.
  at Xamarin.Forms.ListProxy+ProxyEnumerator.MoveNext () [0x00013] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:418 
  at Xamarin.Forms.Internals.TemplatedItemsList`2+<GetEnumerator>d__79[TView,TItem].MoveNext () [0x00085] in <937957814f5d45be82b66795cb584841>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.<CacheDefinedRowHeights>b__6_0 () [0x0007f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:643 
  at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.20/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2879 
  at System.Threading.Tasks.Task.Execute () [0x00010] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.20/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502 <---

It happens definitely since Xamarin.Forms v2.3.5.256-pre6 and still exists in v2.4.0.269-pre2.
It does NOT happen with v2.3.5.239-pre3.
It seems to happen in line 646 in "Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs" while accessing "TemplatedItemsView.TemplatedItems". An "InvalidOperationException" is thrown within the Task.Run() and is not being catched -> Leads to crashing our app!

Because of Bug 58645 I wanted to use v2.4.0 but now I cannot because of this bug here!
I have no time now to add a demonstrating project, so I hope the provided information is enough for you to identify the problem.
Comment 1 Samantha Houts [MSFT] 2017-09-16 01:39:51 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1143
Comment 2 Rui Marinho 2017-09-16 14:44:36 UTC
Should be fixed on 2.4.0-pre3