Selecting From Suggestion List Raises System.InvalidCastException

I have included the SFAutoComplete control in a Xamarin.Forms project that also incorporates MvvmCross. When selecting an item from the suggestion box, I get the error message below. This error only occurs in Android; iOS works just fine. All other functions of the SFautoComplete control seem to work in the Android build. I have the latest of all stable releases.

09-11 07:34:47.606 I/MonoDroid(12861): System.InvalidCastException: Specified cast is not valid.
09-11 07:34:47.606 I/MonoDroid(12861):   at Com.Syncfusion.Autocomplete.SfAutoComplete.PerformCompletion (System.Int32 position, System.Int64 id) [0x002b0] in <ba8241f30dd7450f889d5c709efb5e9b>:0 
09-11 07:34:47.606 I/MonoDroid(12861):   at Com.Syncfusion.Autocomplete.SfAutoComplete.OnTouch (Android.Views.View v, Android.Views.MotionEvent e) [0x00240] in <ba8241f30dd7450f889d5c709efb5e9b>:0 
09-11 07:34:47.606 I/MonoDroid(12861):   at Android.Views.View+IOnTouchListenerInvoker.n_OnTouch_Landroid_view_View_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v, System.IntPtr native_e) [0x00019] in <a10f61e70eeb434e952fef884856c199>:0 
09-11 07:34:47.606 I/MonoDroid(12861):   at (wrapper dynamic-method) System.Object.77(intptr,intptr,intptr,intptr)

8 Replies

PA Paul Anderson S Syncfusion Team September 14, 2018 10:50 AM UTC

Hi Elisa, 
 
Thanks for contacting Syncfusion support. 
 
Query:“ Selecting From Suggestion List Raises System.InvalidCast Exception issue”. 
 
We have analyzed the reported query and we are unable to reproduce the “Cast Invalid Exception” issue. We have prepared a sample in MVVM cross platform. Please check the sample and let we know the issue is reproduced in your side. 
 
 
If you still persist the same issue means, please modify the providing sample which replicate the reported issue to provide appropriate solution for this. 
 
Regards, 
Paul Anderson 



EL Elisa September 14, 2018 01:20 PM UTC

I should have mentioned that I am using the latest stable releases of every nuget package and that I am using a .NETStandard v2.03 for the core. Your provided test app has a core app in a PCL, which limits MVX to using 5.7.0 or earlier versions. Your PCL also limits XF to 2.4. Create a test app on the latest and let me know what you find. (ref. https://visualstudiomagazine.com/articles/2018/05/08/build-a-xamarin.forms-application.aspx)

Thanks!


PA Paul Anderson S Syncfusion Team September 17, 2018 12:30 PM UTC

Hi Elisa, 
 
Sorry for the inconvenience. 
 
We have created the sample with .NET Standard project and added the latest nuget package for Xamarin and MVVM Cross. But we are unable to reproduce the reported exception with SfAutoComplete control. Please have the sample from the following link 
 
 
Could you please provide a modified sample as per your scenario in which the issue can be replicated the reported issue and replication steps if any which will be helpful to  provide appropriate solution for this issue. 
 
Regards, 
Paul Anderson 



EL Elisa September 17, 2018 01:09 PM UTC

Hi Paul,

Thanks for sending another sample project. Unfortunately, this one is not on the latest nuget packages either, and therefore is not structured correctly. Please follow the steps outlined in the article I provided in my previous reply, https://visualstudiomagazine.com/articles/2018/05/08/build-a-xamarin.forms-application.aspx. You should not have any references to MvvmCross.Core, MvvmCross.Bindings, MvvmCross.Platform. You will also see that you should have four total projects, MvxForms.Core, MvxForms.Core.UI, MvxForms.Android, MvxForms.iOS. The use of these projects and the necessary nuget packages are also described in the MvvmCross readme (see attached). I believe there is a version conflict for the Droid support files used by Syncfusion and Mvx but I have not been able to isolate the issue.

Attachment: Mvx_readme_f2cbad65.zip


PA Paul Anderson S Syncfusion Team September 19, 2018 06:11 AM UTC

Hi Elisa, 
 
Sorry for the inconvenience. 
 
We have analyzed the reported issue “Invalid Cast Exception using MVVM cross platforms” based on your details and steps provided for MVVMCross and we are able to reproduce the reported issue at ou end. We have logged a report for this issue and the fix will be available in our upcoming Volume 3 SP-1 release which will be rolled out on October. 
 
Regards, 
Paul Anderson 



EL Elisa September 19, 2018 12:41 PM UTC

Thank you for isolating this issue, Paul. I look forward to the update.


PA Paul Anderson S Syncfusion Team September 19, 2018 12:59 PM UTC

Hi Elisa, 
  
Thanks for the update. 
  
As promised we will fix and include the fix in our Volume 3 SP1 release. 
  
Regards, 
Paul Anderson 



QB quincy batten January 15, 2020 05:57 AM UTC

An InvalidCastException is thrown when cast from one type to another type is not supported. In some reference type conversions , the compiler cannot determine whether a cast will be valid. It is because of the source type cannot be converted to the destination type , so the cast does not succeed.It is important to note that this exception is caused by programming error and should not be handled in a try/catch block; instead, the cause of the exception should be eliminated. C# provides the "is" operator to enable you to test for compatibility before actually performing a cast operation . It will checks if the runtime type of an expression result is compatible with a given type.



Loader.
Up arrow icon