Xamarin IOS Unable to Insert or Get with Children

Issue #146 resolved
Frank created an issue

A range of errors such as below.

 public  class Appointment
    {
        [PrimaryKey]
        public int Id { get; set; }
        public string UserCode { get; set; }

        public string Summary { get; set; }
        public string Description { get; set; }
        public DateTime AppointmentTime { get; set; }

        public string EventTypeCode { get; set; }
        public int? EventStatusCode { get; set; }

        [TextBlob("EventParticipants")]
        public List<string> EventParticipants { get; set; } 


        public string LocationName { get; set; }
        public int? LocationFloorNumber { get; set; }

        public string LocationDescription { get; set; }


        public System.TimeSpan? AppointmentDuration { get; set; }
        }

public  Task SaveAppointments(Appointment appointment)
        {

            return dbasync.InsertOrReplaceWithChildrenAsync(appointment);

        }

Nothing special in the code above. Just fails always with the following type of error.

{System.NullReferenceException: Object reference not set to an instance of an object at SQLiteNetExtensions.Extensions.TextBlob.TextBlobOperations.GetTextBlobChild (System.Object element, System.Reflection.PropertyInfo relationshipProperty) [0x0001f] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.ReadOperations.GetChildRecursive (SQLite.SQLiteConnection conn, System.Object element, System.Reflection.PropertyInfo relationshipProperty, System.Boolean recursive, System.Collections.Generic.Dictionary2[TKey,TValue] objectCache) [0x00079] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.ReadOperations.GetChildrenRecursive (SQLite.SQLiteConnection conn, System.Object element, System.Boolean onlyCascadeChildren, System.Boolean recursive, System.Collections.Generic.Dictionary2[TKey,TValue] objectCache) [0x0003a] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.ReadOperations.GetChildren[T] (SQLite.SQLiteConnection conn, T element, System.Boolean recursive) [0x00000] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren[T] (SQLite.SQLiteConnection conn, System.Linq.Expressions.Expression1[TDelegate] filter, System.Boolean recursive) [0x0002a] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensionsAsync.Extensions.ReadOperations+<>c__DisplayClass0_01[T].<GetAllWithChildrenAsync>b__0 () [0x00029] in <33cde4a1fb7749b2bc0ee82d2e8d1d19>:0 at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <85a0be741dba4068b8b83c4563af7fa8>:0 at System.Threading.Tasks.Task.Execute () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319 --- End of stack trace from previous location where exception was thrown --- at CMSApp.ContentDatabase.GetAppointments () [0x00030] in C:\Users\frank\source\repos\TestXamarinOne\CMSApp\CMSApp\ContentDatabase.cs:75 at CMSApp.ViewModels.SchedulePageViewModel.PopulateAppointments () [0x000e6] in C:\Users\frank\source\repos\TestXamarinOne\CMSApp\CMSApp\ViewModels\SchedulePageViewModel.cs:193 }

{System.ArgumentException: Object of type 'System.String' cannot be converted to type 'System.Collections.Generic.List1[System.String]'. at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00056] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/ReferenceSources/RuntimeType.cs:201 at System.Reflection.RuntimeMethodInfo.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00069] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:454 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00040] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:385 at System.Reflection.RuntimePropertyInfo.SetValue (System.Object obj, System.Object value, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x0005d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimePropertyInfo.cs:469 at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Reflection/PropertyInfo.cs:57 at SQLiteNetExtensions.Extensions.TextBlob.TextBlobOperations.UpdateTextBlobProperty (System.Object element, System.Reflection.PropertyInfo relationshipProperty) [0x00039] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.WriteOperations.RefreshForeignKeys (System.Object element) [0x000b4] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.WriteOperations.UpdateWithChildren (SQLite.SQLiteConnection conn, System.Object element) [0x00000] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.WriteOperations.InsertWithChildrenRecursive (SQLite.SQLiteConnection conn, System.Object element, System.Boolean replace, System.Boolean recursive, System.Collections.Generic.ISet1[T] objectCache) [0x00036] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensions.Extensions.WriteOperations.InsertOrReplaceWithChildren (SQLite.SQLiteConnection conn, System.Object element, System.Boolean recursive) [0x00000] in <9a358a213ad843168007a7a53e69aa05>:0 at SQLiteNetExtensionsAsync.Extensions.WriteOperations+<>c__DisplayClass2_0.<InsertOrReplaceWithChildrenAsync>b__0 () [0x00013] in C:\projects\sqlite-net-extensions\SQLiteNetExtensionsAsync\Extensions\WriteOperations.cs:79 at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2476 at System.Threading.Tasks.Task.Execute () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319 --- End of stack trace from previous location where exception was thrown --- at CMSApp.App+<>c.<SyncContent>b__21_0 () [0x0042b] in C:\Users\frank\source\repos\TestXamarinOne\CMSApp\CMSApp\App.xaml.cs:275 }

Comments (4)

  1. Guillermo Gutiérrez

    TextBlob annotation must reference a String field, but it’s referencing itself, that it’s a List<string> field. You have another field of type string to store the serialized content.

  2. Frank reporter

    Ah. I see. OK I didn’t get that from skimming the docs. Thanks for the super quick response! I will just test this now and make sure it’s ok.

  3. Frank reporter

    OK that works. Many thanks again. Might be worth adding a TextBlob test to the general load/save tests as that was where I was looking for code examples.

  4. Log in to comment