[英]Xamarin Forms with Firebase. Data retrival throwing System.InvalidCastException: 'Specified cast is not valid.'
public async Task<IEnumerable<Users>> GetAllUsers()
{
return (await firebase
.Child("Users")
.OnceAsync<Users>()).Select(item => new Users
{
UserName= item.Object.UserName.ToString(),
Password = item.Object.Password.ToString(),
Role = item.Object.Role.ToString()
}).ToList();
}
I am a beginner to App development.我是应用程序开发的初学者。 While retriving the data from the Firebase Realtime database getting the above error.
从 Firebase 实时数据库检索数据时出现上述错误。 Scratching head for 4 hours.
挠头4小时。 Please help.
请帮忙。
You don't have to cast it toString().您不必将其强制转换为 String()。 Firebase casts types on its own, when you push that object on Firebase Realtime database, it will automatically assign correct type when you pull it back.Get rid of the ToString() on each property and see if that fixes the issue.
Firebase 自行转换类型,当您将该对象推送到 Firebase 实时数据库时,当您将其拉回时,它会自动分配正确的类型。去掉每个属性上的 ToString() 并查看是否可以解决问题。
public async Task<IEnumerable<Users>> GetAllUsers()
{
return (await firebase
.Child("Users")
.OnceAsync<Users>()).Select(item => new Users
{
UserName= item.Object.UserName,
Password = item.Object.Password,
Role = item.Object.Role
}).ToList();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.