question

TimothyGreen-9495 avatar image
0 Votes"
TimothyGreen-9495 asked ExerMine-9390 answered

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

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;
}
}

dotnet-xamarin
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @TimothyGreen-9495 , do you mean your app could work normally several days ago, right? What changes have you made?

0 Votes 0 ·

Yes @JessieZhang-2116, I THOUGHT it did work several days ago. But evidently, that was just for the ios app. It seems as if the android version could've possibly never worked. I finally found a solution. I changed the "new Dictionary<string, Java.Lang.Object>" to "var map = new HashMap();" and used the map.put into insert into Firebase. I just forgot to update. Thank you for responding.

0 Votes 0 ·

Congrats,could you please post your solution and mark it as answered so that it will help others who have similar problem? Thanks in advance.

0 Votes 0 ·
TimothyGreen-9495 avatar image
0 Votes"
TimothyGreen-9495 answered RezaMohamed-2992 published

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you mind posting your entire code here, please? I am not sure what you mean by 'var map = new HashMap()' and how you are using that to add a document to the collection. Thanks

0 Votes 0 ·
ExerMine-9390 avatar image
0 Votes"
ExerMine-9390 answered

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;
}
}

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.