OnPropertyChanged throws exception on android in xamarin.forms app

i'm making an android app with Xamarin.Forms. My iOS app is already finished an released.
My android version will not stop throwing multiple exceptions.

The first exception is a NullReferenceException. This breaks on the following code snipped:

handler(this, new PropertyChangedEventArgs(propertyName));

This is inside my OnPropertyChanged method in a custom NotifyBase class i use for my models.
(Also failing if i remove all but this line from the method.)

The debug output just tells me this:

System.NullReferenceException: Object reference not set to an instance of an object
An unhandled exception occured.
Exception:

This is followed by a TargetInvocationException giving this stack trace:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
07-16 17:37:47.916 I/MonoDroid(27212): UNHANDLED EXCEPTION:        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
07-16 17:37:47.916 I/MonoDroid(27212):07-16 17:37:47.916 I/MonoDroid(27212):   at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212):   at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212):   at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212):   at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:37:47.916 I/MonoDroid(27212):   at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:37:47.916 I/MonoDroid(27212):   at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String propertyName) [0x00087] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Helper\NotifyBase.cs:68 
07-16 17:37:47.916 I/MonoDroid(27212):   at TransMission.Mobile.Helper.NotifyBase.SetField[DateTime] (System.DateTime& field, DateTime value, System.String propertyName) [0x000a2] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Helper\NotifyBase.cs:102 
07-16 17:37:47.916 I/MonoDroid(27212):   at TransMission.Mobile.Core.TransMissionCore.set_Date (DateTime value) [0x00001] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Core\TransMissionCore.cs:275 
07-16 17:37:47.916 I/MonoDroid(27212):   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
07-16 17:37:47.916 I/MonoDroid(27212):   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212):   --- End of inner exception stack trace ---
07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x00062, 0x0033c>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MethodBase.Invoke (object,object[]) <IL 0x00006, 0x0008f>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x00295, 0x0162f>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.Apply (bool) <IL 0x00041, 0x0018b>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Binding.Apply (bool) <IL 0x00027, 0x00113>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject/<>c__DisplayClass1.<SetValueCore>b__0 () <IL 0x00100, 0x00493>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,bool,bool,bool) <IL 0x001b4, 0x009d3>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x001f1, 0x011db>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) <IL 0x0007e, 0x003bf>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Binding.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) <IL 0x0004d, 0x00237>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.ApplyBindings (object) <IL 0x0003a, 0x002af>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject,object) <IL 0x00056, 0x0029b>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.OnBindingContextChanged () <IL 0x0001c, 0x00157>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.View.OnBindingContextChanged () <IL 0x0003b, 0x002a3>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject,object) <IL 0x0005c, 0x002bf>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.set_Parent (Xamarin.Forms.Element) <IL 0x00020, 0x00107>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element) <IL 0x00002, 0x00053>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Page.OnInternalAdded (Xamarin.Forms.VisualElement) <IL 0x00015, 0x000bf>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (object,System.Collections.Specialized.NotifyCollectionC

Unhandled Exception:

Again followed by a TargetInvocationException giving this stack trace:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
07-16 17:41:19.182 E/mono    (27212): 
07-16 17:41:19.182 E/mono    (27212): Unhandled Exception:
07-16 17:41:19.182 E/mono    (27212):   at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.Compon07-16 17:41:19.182 E/mono    (27212): 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
07-16 17:41:19.182 E/mono    (27212):   at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono    (27212):   at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono    (27212):   at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono    (27212):   at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono    (27212):   at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono    (27212):   at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String propertyName
07-16 17:41:19.182 E/mono-rt (27212): [ERROR] FATAL UNHANDLED EXCEPTION: 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
07-16 17:41:19.182 E/mono-rt (27212):   at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono-rt (27212):   at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono-rt (27212):   at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono-rt (27212):   at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono-rt (27212):   at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono-rt (27212):   at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String
Das Programm "Mono" wurde mit Code 0 (0x0) beendet.

As my debug output states this seems to happen for a DateTime property that is set to what seems to be a min value for the DatePicker:

07-16 17:32:45.761 I/mono-stdout(27212): DEBUG     - Changing value from '01.01.0001 00:00:00' to '01.01.1900 00:00:00'.
07-16 17:32:45.771 I/mono-stdout(27212): DEBUG     - Raising PropertyChanged for: 'TransMissionCore.Date'.

My codes works perfectly on iOS. But on Android this is a show stopper.
I tried my app with the latest version of Xamarin.Forms (1.2.1.6229) and with 1.1.1.6206 but this makes no difference.

Is there some kind of workaround? Or am i making a mistake?
Please give advice.

Best Answer

Answers

  • FrTerstappenFrTerstappen DEMember
    edited July 2014

    @StephaneDelcroix‌ You are right. The exception changes after updateing.
    Now i get:

    07-17 09:52:57.169 I/mono-stdout(  699): TRACE     - < Entered member 'ActivationPage.OnAppearing'.
    07-17 09:52:57.190 I/mono-stdout(  699): DEBUG     - Focused the activationCodeEntry.
    07-17 09:52:57.190 I/mono-stdout(  699): TRACE     - > Exited member  'ActivationPage.OnAppearing'.
    07-17 09:54:08.539 D/libEGL  (  699): loaded /system/lib/egl/libGLES_android.so
    07-17 09:54:08.539 D/libEGL  (  699): loaded /system/lib/egl/libEGL_adreno200.so
    07-17 09:54:08.559 D/libEGL  (  699): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
    07-17 09:54:08.559 D/libEGL  (  699): loaded /system/lib/egl/libGLESv2_adreno200.so
    07-17 09:54:08.609 D/memalloc(  699): /dev/pmem: Mapped buffer base:0x5745a000 size:8077312 offset:5988352 fd:63
    07-17 09:54:08.619 D/OpenGLRenderer(  699): Enabling debug mode 0
    An unhandled exception occured.
    Exception:
    
    System.NullReferenceException: Loading...
    07-17 09:56:21.769 I/MonoDroid(  699): UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
    07-17 09:56:21.769 I/MonoDroid(  699): at Xamarin.Forms.Platform.Android.Platform.SetActionBarTextColor () <IL 0x00006, 0x0008c>
    07-17 09:56:21.769 I/MonoDroid(  699): at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarTextColor () <IL 0x00001, 0x00043>
    07-17 09:56:21.769 I/MonoDroid(  699): at Xamarin.Forms.Platform.Android.Platform.OnLayout (bool,int,int,int,int) <IL 0x00004, 0x000ab>
    07-17 09:56:21.769 I/MonoDroid(  699): at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (bool,int,int,int,int) <IL 0x0001b, 0x000d3>
    07-17 09:56:21.769 I/MonoDroid(  699): at Android.Views.ViewGroup.n_OnLayout_ZIIII (intptr,intptr,bool,int,int,int,int) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.ViewGroup.cs:3274
    07-17 09:56:21.769 I/MonoDroid(  699): at (wrapper dynamic-method) object.f1a8f2e2-949c-4a41-a4f6-06b1c76636ca (intptr,intptr,bool,int,int,int,int) <IL 0x0002f, 0x00093>
    Unhandled Exception:
    
    System.NullReferenceException: Object reference not set to an instance of an object
    07-17 09:56:24.872 E/mono    (  699): 
    07-17 09:56:24.872 E/mono    (  699): Unhandled Exception:
    07-17 09:56:24.872 E/mono    (  699):   at Android.Views.ViewGroup.n_OnLayout_ZIIII (IntPtr jnienv, IntPtr native__this, Boolean changed, 07-17 09:56:24.872 E/mono    (  699): System.NullReferenceException: Object reference not set to an instance of an object
    07-17 09:56:24.872 E/mono    (  699):   at Xamarin.Forms.Platform.Android.Platform.SetActionBarTextColor () [0x00000] in <filename unknown>:0 
    07-17 09:56:24.872 E/mono    (  699):   at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarTextColor () [0x00000] in <filename unknown>:0 
    07-17 09:56:24.872 E/mono    (  699):   at Xamarin.Forms.Platform.Android.Platform.OnLayout (Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) [0x00000] in <filename unknown>:0 
    07-17 09:56:24.872 E/mono    (  699):   at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) [0x00000] in <filename unknown>:0 
    07-17 09:56:24.872 E/mono    (  699):   at Android.Views.ViewGroup.n_OnLayout_ZIIII (IntPtr jnienv, IntPtr native__this, Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.ViewGroup.cs:3274 
    07-17 09:56:24.872 E/mono    (  699):   at (wrapper dynamic-method) object:f1a8f2e2-949c-4a41-a4f6-06b1c76636ca (intptr,intp
    07-17 09:56:24.872 E/mono-rt (  699): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
    07-17 09:56:24.872 E/mono-rt (  699):   at Xamarin.Forms.Platform.Android.Platform.SetActionBarTextColor () [0x00000] in <filename unknown>:0 
    07-17 09:56:24.872 E/mono-rt (  699):   at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarTextColor () [0x00000] in <filename unknown>:0 
    07-17 09:56:24.872 E/mono-rt (  699):   at Xamarin.Forms.Platform.Android.Platform.OnLayout (Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) [0x00000] in <filename unknown>:0 
    Das Programm "Mono" wurde mit Code 0 (0x0) beendet.
    

    This seems to be the SetActionBarTextColor error which i have seen sometimes in this forum.
    But i have not seen a solution working for me. My app has a navigation page (or more specific a page derived from navigationpage) as root. This page pushes my content and if not activated a activation form modal.

    Is this fixable? I need to release this week.
    Can somebody solve this?

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    @FrTerstappen‌ : relieved to hear that it's not the same error. 1.2.2 should hit pre-release soon. in the meantime, wrapping your page in a NavigationPage works, see other threads on how to

Sign In or Register to comment.