System.InvalidCastException: 'Specified cast is not valid. Xamarin.Forms

NeidennX 1 Reputation point

Hi Everyone ! i have this project in which i need to Retrieve a list of data, when i click the Retrieve Button, the app enters in break mode and shows me an error saying

System.InvalidCastException: 'Specified cast is not valid.'

Accroding to what i've found the issue is with the ListView block, but im not quite sure, please find it here attached

            <ListView x:Name="ListEstudiantes">  
                        <TextCell Text="{Binding Name}">                                

If you need a Demo please let me know!


A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,928 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Alessandro Caliaro 3,436 Reputation points

    You must have an ObservableCollection and set ItemSource property to the collection, otherwise your listview does not know data to visualize

    1 person found this answer helpful.

  2. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 44,161 Reputation points Microsoft Vendor


    Welcome to our Microsoft Q&A platform!

    the things is that i need to Search an Student by an specific condition and display the information in the Text Fields, but when i do it the exception pops up, but the List >View is working now properly

    Do you meen when you click the btnRetrive, when you will get the Specified cast is not valid. Xamarin.Forms?

    If so, you should change txtCedula to txtCedula.Text like following code. Because txtCedula is entry, if you want to get the text from the entry, you could add Text property.

    var Estudiante = await FireBaseHelper.GetEstudiante(Convert.ToInt32(txtCedula.Text)).ConfigureAwait(true);

    Note: If you solved this issue, please delete the demo link in the comment, it contains your privacy information, If you have any other issues about firebase, you do not share the baseUrl. Just emty it, then share test record's data-structor in firebase DB.

    Best Regards,

    Leon Lu

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.