Bug 60805 - CarouselView Specified cast is not valid Exception
Summary: CarouselView Specified cast is not valid Exception
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-11-22 11:24 UTC by Ali
Modified: 2017-12-15 18:29 UTC (History)
3 users (show)

Tags: needs_repro
Is this bug a regression?: ---
Last known good build:

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:

Description Ali 2017-11-22 11:24:01 UTC
I'm using my own CarouselView class to implement auto-sliding, After updating Xamarin.Forms to 2.5 and `CarouselView.FormsPlugin` to `5.0.0` and after sliding once, for the second time I get Exception says: "Specified cast is not valid".

 public class LavaSlider : CarouselView.FormsPlugin.Abstractions.CarouselViewControl
        int pos = 0;
        public static readonly BindableProperty CountProperty = 
            BindableProperty.Create("Count", typeof(int),typeof(LavaSlider), 0);
        public int Count
            get => (int)GetValue(CountProperty) ;
            set => SetValue(CountProperty, value);

        public LavaSlider()
            Device.StartTimer(TimeSpan.FromSeconds(5), () =>
                if (pos == Count) pos = 0;
                Position = pos; //Exception occurs here!  ->  "Specified cast is not valid"
                return true;

Before updating libraries I didn't get this error.
Comment 1 Paul DiPietro [MSFT] 2017-11-22 16:03:03 UTC
Can you please give us a complete, minimized reproduction?
Comment 2 pinkelephantdev 2017-11-22 16:28:43 UTC
The same happens to me with a tableview 
Project Updated to 2.5(from 2.3) and when fast scrolling (So when re-use cells is going on) in a tableview with different edit components like entry en date fields.

Everytime hard crash on iOS in Main.cs: Specified cast is not valid.
Trying to create a small project to reproduce it tomorrow

For now , Call stack:

Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.VisualElementRenderer<Xamarin.Forms.Picker>.Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement(Xamarin.Forms.Label element) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.RendererPool.UpdateRenderers(Xamarin.Forms.Grid newElement) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.RendererPool.UpdateNewElement(Xamarin.Forms.Grid newElement) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.VisualElementPackager.SetElement(Xamarin.Forms.Grid oldElement, Xamarin.Forms.Grid newElement) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.VisualElementPackager.OnRendererElementChanged(Xamarin.Forms.Platform.iOS.Platform.DefaultRenderer sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs args) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.VisualElementRenderer<Xamarin.Forms.VisualElement>.OnElementChanged(Xamarin.Forms.Platform.iOS.ElementChangedEventArgs<Xamarin.Forms.VisualElement> e) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.VisualElementRenderer<Xamarin.Forms.VisualElement>.SetElement(Xamarin.Forms.Grid element) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.VisualElementRenderer<Xamarin.Forms.VisualElement>.Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement(Xamarin.Forms.Grid element) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.ViewCellRenderer.ViewTableCell.UpdateCell(Xamarin.Forms.ViewCell cell) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.ViewCellRenderer.ViewTableCell.set_ViewCell(Xamarin.Forms.ViewCell value) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.ViewCellRenderer.GetCell(Xamarin.Forms.ViewCell item, Xamarin.Forms.Platform.iOS.ViewCellRenderer.ViewTableCell reusableCell, UIKit.UITableView tv) in 
XFGloss.iOS.dll!XFGloss.iOS.Renderers.XFGlossViewCellRenderer.GetCell(Xamarin.Forms.ViewCell item, Xamarin.Forms.Platform.iOS.ViewCellRenderer.ViewTableCell reusableCell, UIKit.UITableView tv) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.CellTableViewCell.GetNativeCell(UIKit.UITableView tableView, Xamarin.Forms.ViewCell cell, bool recycleCells, string templateId) in 
Xamarin.Forms.Platform.iOS.dll!Xamarin.Forms.Platform.iOS.TableViewModelRenderer.GetCell(UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) in 
Xamarin.iOS.dll!UIKit.UIApplication.UIApplicationMain() in 
Xamarin.iOS.dll!UIKit.UIApplication.Main(string[] args, System.IntPtr principal, System.IntPtr delegate) in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIApplication.cs:79
Xamarin.iOS.dll!UIKit.UIApplication.Main(string[] args, string principalClassName, string delegateClassName) in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIApplication.cs:63
Pink_CRM.iOS.exe!Pink_CRM.iOS.Application.Main(string[] args) in /TEMP/BACKUP CRM 1380/Versie 1.0/Pink_CRM/Pink_CRM.iOS/Main.cs:17
Comment 3 pinkelephantdev 2017-11-24 11:02:31 UTC
I have created a small test project, parts of my original project.

A normal tableview where objects are generated onto it

- Open App (Simulator 8 Ios 11 or device)
- Tableview loaded
- Scroll FAST (Throw view with mouse so reuse from cells is triggered) from top to bottom and bottom to top for several times 

Error occurred :
System.InvalidCastException has been thrown
Specified cast is not valid

Looks like the reuse from Cells is not working correctly

- OK
- Crash
- Crash

TEST Project:


=== Visual Studio Community 2017 for Mac ===

Version 7.2.2 (build 11)
Installation UUID: 36d4a3ef-bbf4-42c0-922c-ab3c70c3b2e9
	Mono (2017-06/1f4613aa1ac) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504010006

=== NuGet ===


=== .NET Core ===

Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.5.6
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 9.1 (13532)
Build 9B55

=== Xamarin.iOS ===

Version: (Visual Studio Community)
Hash: 51128b8c
Branch: xcode9.1
Build date: 2017-10-31 22:42:13-0400

=== Xamarin.Android ===

Version: (Visual Studio Community)
Android SDK: /Users/PinkDevelopment/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.4 (API level 19)
		5.1 (API level 22)
		6.0 (API level 23)
		7.0 (API level 24)
		7.1 (API level 25)
		8.0 (API level 26)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.5
SDK Build Tools Version: 25.0.3

Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here:

=== Xamarin.Mac ===

Version: (Visual Studio Community)

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 702020011
Git revision: b604c37c5a4a2f0919b45ffbe2aaad9fe040af31
Build date: 2017-11-01 08:31:43-04
Xamarin addins: d57dc14cbd4eb166ee62bab585965ab78d3650bc
Build lane: monodevelop-lion-d15-4

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
    Thu Jun 15 17:36:27 PDT 2017
    root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Comment 4 pinkelephantdev 2017-11-24 11:07:16 UTC
Recording from my simulator:

Comment 5 Paul DiPietro [MSFT] 2017-12-15 18:29:48 UTC
The reproduction link is no longer valid. For upkeep purposes, as we are moving to GitHub issues (https://github.com/xamarin/Xamarin.Forms/issues), I would suggest filing an issue there if you're still able to reproduce this with minimal custom code, or if this issue affects the CarouselView plugin as the original message mentions, perhaps commenting here on the CarouselView PR: https://github.com/xamarin/Xamarin.Forms/pull/853. I think that might possibly get more visibility.