Casting firabase data to HashMap


I am making an app wich uses firebase database.
To retrieve data from the database I did the following wich worked perfectly fine.

    private void AccountData_Load()
        //Check user login
        if (auth == null)
            auth = FirebaseAuth.GetInstance(Global.firebaseApp());
        //Get account info
        if (auth.CurrentUser != null)
            //Get e-mail
            txtEmail.Text = auth.CurrentUser.Email;
            //Setup database
            mDatabase = FirebaseDatabase.GetInstance(Global.firebaseApp()).GetReference("Users");

    public void OnDataChange(DataSnapshot snapshot)
        //Get data from database
        var AccountDataMap = (Java.Util.HashMap)snapshot.GetValue(true);

        AccountModel AccountData = new AccountModel(AccountDataMap);

        //Fill in address
        txtAddress.Text = AccountData.Address;
        txtName.Text = AccountData.Firstname + " " + AccountData.Lastname;

After updating to the latest version of xamarin android, I can't do this anymore.
I get an invalid cast exception when retrieving data from Firebase. But Firebase returns an HashMap object.

I think it has something to do with the following bug that was fixed in Xamarin Android (my current version is
58303: Java.Util.HashMap is mapped to Android.Runtime.JavaDictionary in binding generator

If I cast the snapshot.GetValue(true) to Android.Runtime.JavaDictionary, I get no cast error.
The problem with Android.Runtime.JavaDictionary is that I can not get the data inside using a Get(string) function like I would do with a HashMap.

Can this be fixed ?

Best regards,

Olivier Verhaegen

Sign In or Register to comment.