- edited description
NullReferenceException on GetAllWithChildrenAsync and InsertWithChildrenAsync
Im having trouble working with TextBloobed fields and getting a NullReferenceException on all Read and Write methods in ExtensionsAsync.
I have a model CaseRecord which contains fields with Object Item and List<Item>:
public class CaseRecord
{
[PrimaryKey, AutoIncrement]
public int caseId { get; set; }
[TextBlob("ProcItemBloobed")]
public Item ProcItem { get; set; }
public string ProcItemBloobed { get; set; }
[TextBlob("PreItemBloobed")]
public List<Item> PreItem { get; set; }
public string PreItemBloobed { get; set; }
[TextBlob("ModifiersBloobed")]
public List<Item> Modifiers { get; set; }
public string ModifiersBloobed { get; set; }
[TextBlob("AdditionalBloobed")]
public List<Item> AdditionalItems { get; set; }
public string AdditionaBloobed { get; set; }
public bool Archived { get; set; } = false;
}
public class Item
{
public string ItemNumber { get; set; }
public string Description { get; set; }
public string LongDescription { get; set; }
public int Units { get; set; }
public string Group { get; set; }
}
Im accessing like this:
private SQLiteAsyncConnection _connection;
public SQLiteCaseRecordStore(ISQLiteDb db)
{
_connection = db.GetConnection();
}
public async Task AddCaseRecord(CaseRecord record)
{
await _connection.CreateTableAsync<CaseRecord>();
await SQLiteNetExtensionsAsync.Extensions.WriteOperations.InsertWithChildrenAsync(_connection, record);
}
public async Task<List<CaseRecord>> GetCaseRecords()
{
await _connection.CreateTableAsync<CaseRecord>();
return await SQLiteNetExtensionsAsync.Extensions.ReadOperations.GetAllWithChildrenAsync<CaseRecord>(_connection, r => r.Archived != true);
}
However I get the following exception
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 C:\projects\sqlite-net-extensions\SQLiteNetExtensions\Extensions\TextBlob\TextBlobOperations.cs:34
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 C:\projects\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:198
at SQLiteNetExtensions.Extensions.ReadOperations.GetChildrenRecursive (SQLite.SQLiteConnection conn, System.Object element, System.Boolean onlyCascadeChildren, System.Boolean recursive, System.Collections.Generic.Dictionary
2[TKey,TValue] objectCache) [0x0003a] in C:\projects\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:169
at SQLiteNetExtensions.Extensions.ReadOperations.GetChildren[T] (SQLite.SQLiteConnection conn, T element, System.Boolean recursive) [0x00000] in C:\projects\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:110
at SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren[T] (SQLite.SQLiteConnection conn, System.Linq.Expressions.Expression1[TDelegate] filter, System.Boolean recursive) [0x0002a] in C:\projects\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:52
at SQLiteNetExtensionsAsync.Extensions.ReadOperations+<>c__DisplayClass0_0
1[T].<GetAllWithChildrenAsync>b__0 () [0x00029] in C:\projects\sqlite-net-extensions\SQLiteNetExtensionsAsync\Extensions\ReadOperations.cs:40
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:545
at System.Threading.Tasks.Task.Execute () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2344
at PrivateAnaesthesiaStandard.SQLiteCaseRecordStore+<GetCaseRecords>d__3.MoveNext () [0x000fd] in /Users/davidbell/Projects/privateanaesthesia/PrivateAnaesthesiaStandard/Persistence/SQLiteCaseRecordStore.cs:31
at PrivateAnaesthesiaStandard.SchedulePageViewModel+<LoadData>d__24.MoveNext () [0x00036] in /Users/davidbell/Projects/privateanaesthesia/PrivateAnaesthesiaStandard/ViewModels/SchedulePageViewModel.cs:59
at PrivateAnaesthesiaStandard.SchedulePageViewModel+<<-ctor>b__22_0>d.MoveNext () [0x0001f] in /Users/davidbell/Projects/privateanaesthesia/PrivateAnaesthesiaStandard/ViewModels/SchedulePageViewModel.cs:40
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1023
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15/src/Xamarin.iOS/Foundation/NSAction.cs:178
at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15/src/Xamarin.iOS/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15/src/Xamarin.iOS/UIKit/UIApplication.cs:63
at PrivateAnaesthesiaStandard.iOS.Application.Main (System.String[] args) [0x00001] in /Users/davidbell/Projects/privateanaesthesia/PrivateAnaesthesiaStandard.iOS/Main.cs:17
Can anyone help?
Comments (7)
-
reporter -
reporter - edited description
-
reporter - marked as minor
- edited description
-
reporter - edited description
-
reporter - changed status to resolved
My apoliges. I have resolved. It was a typo in the AdditionalBloobed string field
-
What was the typo? I am getting a null ref exception on both insert and get and nothing to indicate why.
-
Hmm. Now I am getting this error. Isn’t this just some iOS + Reflection incompatibility?
{System.ArgumentException: Object of type 'System.String' cannot be converted to type 'System.Collections.Generic.List`1[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.ISet`1[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 }
- Log in to comment