TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
211 stars 49 forks source link

Array of number not loading to List<double> in MAUI #276

Closed corne-du-plooy closed 6 months ago

corne-du-plooy commented 6 months ago

Hi Tobias,

As background: I am in the process of porting from Xamarin to Maui and running into an issue where my firebase doc contains an array of numbers.

In Xamarin Forms I used https://github.com/f-miyu/Plugin.CloudFirestore which worked 100%. My web app uses the firebase npm module.

In the web app, the array is declared as: ele: number[] , and in Maui, its declared as:

[FirestoreProperty("ele")]
   public List<double> ele { get; set; }.

This worked 100% of Xamarin.Forms, but for some documents, when I try and retrieve the data (MyObject r = documentChange.DocumentSnapshot.Data; where ele is declared as a public property), the following execution is thrown:

The value "85" is not of type "System.Double" and cannot be used in this generic collection. (Parameter 'value')

The value of 85 varies based on the document. This is an array of elevations, and I have checked that the firestore document stores it as a number.

The full stack of the error is:

 at System.Collections.Generic.List`1[[System.Double, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].System.Collections.IList.Add(Object item)
   at Plugin.Firebase.Firestore.Platforms.Android.Extensions.ListExtensions.ToList(JavaList this, Type targetType)
   at Plugin.Firebase.Firestore.Platforms.Android.Extensions.JavaObjectExtensions.ToObject(Object this, Type targetType)
   at Plugin.Firebase.Firestore.Platforms.Android.Extensions.JavaObjectExtensions.Cast(IDictionary this, Type targetType, String documentId)
   at Plugin.Firebase.Firestore.Platforms.Android.Extensions.JavaObjectExtensions.Cast[Route](IDictionary`2 this, String documentId)
   at Plugin.Firebase.Firestore.Platforms.Android.DocumentSnapshotWrapper`1[[GRVL.Data.Route, GRVL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_Data()

Any pointers as to what might be causing this, or how to fix this would be greatly appreciated.

Thanks a stack

TobiasBuchholz commented 6 months ago

Hi, sorry for the late response! I was able to find the reason for this issue and have just released a fix for it in Plugin.Firebase.Firestore 2.0.7 or Plugin.Firebase 2.0.13 🚀