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

NeidennX 1 Reputation point
2020-12-26T01:41:00.697+00:00

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">  
                <ListView.ItemTemplate>  
                    <DataTemplate>  
                        <TextCell Text="{Binding Name}">                                
                        </TextCell>  
                    </DataTemplate>  
                </ListView.ItemTemplate>  
            </ListView>  
                  

If you need a Demo please let me know!

51341-2020-12-25-19-03-32-appmatriculav5-debugging-micro.png

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

2 answers

Sort by: Most helpful
  1. Alessandro Caliaro 4,186 Reputation points
    2020-12-26T18:40:13.077+00:00

    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.) 76,386 Reputation points Microsoft Vendor
    2020-12-28T05:44:51.657+00:00

    Hello,​

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.