Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSObjectExtentions NullReferenceException crash #351

Open
barrysohl opened this issue Oct 8, 2024 · 1 comment
Open

NSObjectExtentions NullReferenceException crash #351

barrysohl opened this issue Oct 8, 2024 · 1 comment

Comments

@barrysohl
Copy link

We have a FirestoreObject that causes a NullReferenceException deep in Firestore code during serialization for SetDataAsync. Statckrace is below.

The crash occurs in the following spot at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.NSObjectExtensions.ToNSObject where @this is null.

public static NSObject ToNSObject(this object @this)
    {
      switch (@this)

and then crashes further on in the method when it hits this line:
interpolatedStringHandler.AppendFormatted<Type>(@this.GetType());

The same thing happens whether the call is batched or not, in case that matters. Any ideas? Thanks in advance!


System.NullReferenceException: Object reference not set to an instance of an object.
   at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.NSObjectExtensions.ToNSObject(Object this)
   at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.ListExtensions.ToNSArray(IList this)
   at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.NSObjectExtensions.ToNSObject(Object this)
   at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.DictionaryExtensions.ToDictionary(Object this)
   at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.NSObjectExtensions.ToNSObject(IFirestoreObject this)
   at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.NSObjectExtensions.ToNSObject(Object this)
   at Plugin.Firebase.Firestore.Platforms.iOS.Extensions.DictionaryExtensions.ToDictionary(Object this)
   at Plugin.Firebase.Firestore.Platforms.iOS.WriteBatchWrapper.SetData(IDocumentReference document, Object data, SetOptions options)
--- user code

@barrysohl
Copy link
Author

A little bit more info on this one... This happens if there is an IList property within an IFirestoreObject that is in turn a property witihn an IFirestoreObject (see code below). We have had trouble in multiple places with our hierarchical data model that were not a problem previously with Plugin.Firestore.

public class ClassA : IFirestoreObject
{
      [FirestoreProperty("classb")] public ClassB { get; set; }
}

public class ClassB : IFirestoreObject
{
      [FirestoreProperty("strings")] public IList<string> Strings { get; set; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant