Adding document to Cloud Firestore with xamarin.android not working any longer. Can someone help?

TimEdGreen 96 Reputation points
2020-12-19T14:22:44.513+00:00

Hi, I'm new to Xamarin and have been working on inserting records(documents) to Cloud Firestore. It one point about three days ago it was working without an issue. I was able to add. Now I'm getting error messages. It only happens in xamarin.android, xamarin.ios is still working. Any help would be greatly appreciated.

I get the error: CS1503: Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, Java.Lang.Object>' to 'Java.Lang.Object'

See method below:

public bool InsertPost(Models.Post post)
{
try
{
var collection = Firebase.Firestore.FirebaseFirestore.Instance.Collection("Posts");
var postDoc = new Dictionary<string, Java.Lang.Object>
{
{ "UserId", Firebase.Auth.FirebaseAuth.Instance.CurrentUser.Uid },
{ "Title", post.Title },
{ "Detais", post.Details },
{ "PostDate", DateTimetoNativeDate(DateTime.Now) }
};
collection.Add(postDoc);

return true;
}
catch (Exception ex)
{
return false;
}
}

Developer technologies | .NET | Xamarin
{count} votes

Accepted answer
  1. TimEdGreen 96 Reputation points
    2020-12-23T21:58:45.973+00:00

    I changed the "new Dictionary<string, Java.Lang.Object>" to "var map = new HashMap();" and used the map.put into insert into Firebase.


1 additional answer

Sort by: Most helpful
  1. ExerMine 1 Reputation point
    2021-05-01T21:38:59.903+00:00

    public bool InsertPost(Models.Post post)
    {
    try
    {
    var collection = Firebase.Firestore.FirebaseFirestore.Instance.Collection("Posts");
    var postDoc = new Dictionary<string, Java.Lang.Object>
    {
    { "UserId", Firebase.Auth.FirebaseAuth.Instance.CurrentUser.Uid },
    { "Title", post.Title },
    { "Detais", post.Details },
    { "PostDate", DateTimetoNativeDate(DateTime.Now) }
    };

    ////////////////////////////////////
    //collection.Add(postDoc);
    // changed to ->
    collection.Add(new HashMap(postDoc));

    return true;
    }
    catch (Exception ex)
    {
    return false;
    }
    }

    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.