NullReferenceException is thrown by FastDeepCloner in Xamarin.iOS mobile app
Closed this issue · 2 comments
Hi,
I used the FastDeepCloner in a Xamarin.Forms mobile app for iOS and Android.
Some time ago the iOS app started crashing. Maybe it is related to the updated version of Xamarin.iOS framework. Or maybe it is related to the updated version of iOS. I don't.
Please note, that the Android app works as expected.
Mobile device: iPhone 7 Plus
iOS version: 13.2
Xamarin.Forms version: 3.2.0.839982
Xamarin.iOS version: 13.2.0.47
Mono version: 6_4_0
iOS SDK: iPhoneOS13.2.sdk
FastDeepCloner version: 1.3.0
The FastDeepCloner call is inside our custom .NET Standard 2.0 library.
The FastDeepCloner call is simple:
var clonedMyObj = FastDeepCloner.DeepCloner.Clone(myObj);
The myObj is a class with the following fields:
{ "Account": { "AccountNumber": "1-10HG5N0", "City": "Masku", "Country": "Finland", "CustomerContacts": null, "Id": "f4db0e33-9be0-41dc-a057-e12061e15554", "IsDeleted": false, "LastUpdated": "2017-08-04T09:03:24+00:00", "ModificationNum": 29, "Name": "Ablemans Oy", "PinX": null, "PinY": null, "PostalCode": "21250", "SiebelId": "1-10HG5N0", "State": null, "StreetAddress": "Härjänkurkuntie 46" }, "AccountId": "f4db0e33-9be0-41dc-a057-e12061e15554", "AccountSiebelId": "1-10HG5N0", "AgreementNo": "", "Attachments": [], "BillingTypeCode": "Time \u0026 Material", "CustomerPurchaseOrder": null, "CustomerPurchaseOrderRequired": true, "CustomerSignatures": [], "DailyInspectionIsSold": false, "Employees": [], "ExpenseTypes": [], "Id": "492f22d2-782b-4080-8776-af89941aa2d4", "InternalComments": null, "IsDeleted": false, "IsExpanded": false, "LastUpdated": "0001-01-01T00:00:00+00:00", "ManliftCode": null, "MarkedToDelete": false, "MarkedToDeleteTimestamp": null, "ModificationNum": 4, "OpenedPlannedDate": "2019-03-10T08:00:00", "OriginalServiceRequestId": null, "OriginalServiceRequestSiebelId": "", "PartStatusCode": null, "Parts": [], "PlanningActivities": [{ "Id": "6f315bd4-812d-4c6d-b5e2-59420697e2f5", "IsDeleted": false, "LastUpdated": "0001-01-01T00:00:00+00:00", "ModificationNum": 0, "ServiceRequestId": "492f22d2-782b-4080-8776-af89941aa2d4", "SiebelId": "1-14ENIQS7", "VisitTime": "2019-03-10T08:00:00" } ], "PrimaryContactId": "f0cd958e-9dcd-41a1-a6ee-f070b4a07830", "PrimaryContactSiebelId": null, "RentalEquipmentCode": null, "Reports": [], "SPCode": "SP23 - On-call service", "SPCodeDisplayLabel": "SP23 - On-call services", "SRDescription": "6648", "SRNumber": "1-87955822102", "SalesCaseSiebelId": null, "ServiceProducts": "On call repairs, MAINMAN Planned Maintenance", "ServiceRequestId": "492f22d2-782b-4080-8776-af89941aa2d4", "SiebelId": "1-14EMMIOM", "Status": "In Progress", "TestWeightsCode": null, "TotalEstimate": 8, "VisitReview": null, "WorkPackageId": null, "Workpackages": [{ "Actions": null, "ActualStartDate": "2020-01-13T20:48:01", "AgreementReportingLevelCode": null, "AssetId": "a24e91e0-6bf2-42f5-8ba3-bd54785a7a7d", "AssetInformation": null, "Components": null, "CreatedManually": true, "Description": "6648", "EstimatedHours": 4, "ExpenseEntries": null, "FieldInstructions": "", "HasCustomerSignature": false, "HasTechSignature": false, "Id": "4c226f2f-bee1-4e15-96b3-6f721a31db08", "IsDeleted": false, "LastUpdated": "0001-01-01T00:00:00+00:00", "Loaded": false, "Measurements": null, "ModificationNum": 3, "OriginalWorkPackageId": null, "OriginalWorkPackageSiebelId": null, "OwnerId": "1-14EIWNH6", "PlannedDate": "2019-03-10T08:00:00", "Readings": null, "ServiceProducts": null, "ServiceRequest": null, "ServiceRequestId": "492f22d2-782b-4080-8776-af89941aa2d4", "SiebelAssetId": "1-11RCLLL", "SiebelId": "1-14ENIPQE", "StatusCode": "In Progress", "Tasks": null, "TimeEntries": null, "WPNumber": "1-14ENIPQE" }, { "Actions": null, "ActualStartDate": null, "AgreementReportingLevelCode": null, "AssetId": "1ab0b022-d415-4e71-ae83-3d7d3425d990", "AssetInformation": null, "Components": null, "CreatedManually": true, "Description": "6648", "EstimatedHours": 4, "ExpenseEntries": null, "FieldInstructions": "", "HasCustomerSignature": false, "HasTechSignature": false, "Id": "9590cb67-5d89-4af5-946b-cdf8b2fc87c2", "IsDeleted": false, "LastUpdated": "0001-01-01T00:00:00+00:00", "Loaded": false, "Measurements": null, "ModificationNum": 0, "OriginalWorkPackageId": null, "OriginalWorkPackageSiebelId": null, "OwnerId": "", "PlannedDate": "2019-03-10T08:00:00", "Readings": null, "ServiceProducts": null, "ServiceRequest": null, "ServiceRequestId": "492f22d2-782b-4080-8776-af89941aa2d4", "SiebelAssetId": "1-11OJR9E", "SiebelId": "1-14ENIKB3", "StatusCode": "Unscheduled", "Tasks": null, "TimeEntries": null, "WPNumber": "1-14ENIKB3" } ] }
And the exception is:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object at FastDeepCloner.FastDeepClonerProperty..ctor (System.Reflection.PropertyInfo property) [0x000cf] in <ce0c03c57cf64fd38756e8b69a104181>:0 at FastDeepCloner.FastDeepClonerCachedItems+<>c__DisplayClass28_0.<GetFastDeepClonerProperties>b__2 (System.Reflection.PropertyInfo x) [0x0000c] in <ce0c03c57cf64fd38756e8b69a104181>:0 at System.Linq.Enumerable+WhereArrayIterator
1[TSource].ToList () [0x00019] in <69f79cbb9a4c4409847837a879ee8812>:0
at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable1[T] source) [0x0001f] in <69f79cbb9a4c4409847837a879ee8812>:0 at FastDeepCloner.FastDeepClonerCachedItems.GetFastDeepClonerProperties (System.Type primaryType) [0x000ae] in <ce0c03c57cf64fd38756e8b69a104181>:0 at FastDeepCloner.ClonerShared.Clone (System.Object objectToBeCloned) [0x00134] in <ce0c03c57cf64fd38756e8b69a104181>:0 at FastDeepCloner.ClonerShared.ReferenceTypeClone (System.Collections.Generic.Dictionary
2[TKey,TValue] properties, System.Type primaryType, System.Object objectToBeCloned, System.Object appendToValue) [0x000af] in :0
at FastDeepCloner.ClonerShared.Clone (System.Object objectToBeCloned) [0x00356] in :0
at FastDeepCloner.DeepCloner.Clone[T] (T objectToBeCloned, FastDeepCloner.FieldType fieldType) [0x00006] in :0
at KC.Mobility.Technician.PageModels.ServiceRequest.ServiceRequestsPageModel+<>c.<get_GroupedList>b__42_3 (KC.Mobility.Technician.DataModel.PlanningActivity act, KC.Mobility.Technician.Models.ServiceRequest.ServiceRequestModel sr) [0x00001] in /Users/runner/runners/2.163.1/work/1/s/MobileApp/KC.Mobility.Technician/PageModels/ServiceRequest/ServiceRequestsPageModel.cs:136
at System.Linq.Enumerable+d__814[TOuter,TInner,TKey,TResult].MoveNext () [0x000cb] in <69f79cbb9a4c4409847837a879ee8812>:0 at System.Collections.Generic.List
1[T].AddEnumerable (System.Collections.Generic.IEnumerable1[T] enumerable) [0x00059] in <aedd57cfa7174b1b89f01dd6015f4050>:0 at System.Collections.Generic.List
1[T]..ctor (System.Collections.Generic.IEnumerable1[T] collection) [0x00062] in <aedd57cfa7174b1b89f01dd6015f4050>:0 at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable
1[T] source) [0x00018] in <69f79cbb9a4c4409847837a879ee8812>:0
at KC.Mobility.Technician.PageModels.ServiceRequest.ServiceRequestsPageModel.get_GroupedList () [0x0003d] in /Users/runner/runners/2.163.1/work/1/s/MobileApp/KC.Mobility.Technician/PageModels/ServiceRequest/ServiceRequestsPageModel.cs:133
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395
--- End of inner exception stack trace ---
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00081] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:409
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53
at Xamarin.Forms.BindingExpression+BindingExpressionPart.TryGetValue (System.Object source, System.Object& value) [0x00049] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:638
at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001ab] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:160
at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:57
at Xamarin.Forms.BindingExpression+BindingExpressionPart.b__49_0 () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:615
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.2.0.47/src/Xamarin.iOS/Foundation/NSAction.cs:152
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/13.2.0.47/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.2.0.47/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at KC.Mobility.Technician.iOS.Application.Main (System.String[] args) [0x00001] in /Users/runner/runners/2.163.1/work/1/s/MobileApp/Mobile Clients/KC.Mobility.Technician.iOS/Main.cs:18
`
Could you tell me please, what is the issue and can I fix it?
Thank you in advance!
Best Regards,
Aleksandrs
I have added the FastDeepCloner source code to my project. And, after debugging, I realized that the issue is in the FastDeepClonerProperty class, at the constructor:
internal FastDeepClonerProperty(PropertyInfo property)
at line 76:
IsVirtual = property.GetMethod.IsVirtual;
And the property that causes this exception is the Capacity property of the List<> class. Because the PropertyInfo class of the Int32 Capacity property doesn't have the GetMethod property.
I don't know why this Capacity property is passed to the FastDeepClonerProperty class on the iOS platform. Because it is not passed there on the Android platform.
thank you for pointing out the issue, i have fixed the error in version 1.3.1