I'm using Xamarin Forms 4.2.0 and utilizing Xamarin.Forms Shell. Pressing the back button seems to work find when navigating through the various screens in my app, however, when I press back to exit the app when debugging I get a NullReferenceException:
09-30 14:49:52.866 D/Mono ( 1085): Loading reference 10 of /storage/emulated/0/Android/data/com.companyname.agentconnectmobile/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:52.866 D/Mono ( 1085): Assembly Ref addref Xamarin.Forms.Platform.Android[0x799acc0e00] -> System.Runtime.Serialization[0x7935aa8d00]: 3 09-30 14:49:52.866 D/Mono ( 1085): Loading reference 1 of System.Runtime.Serialization.dll asmctx DEFAULT, looking for System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:52.866 D/Mono ( 1085): Assembly Ref addref System.Runtime.Serialization[0x7935aa8d00] -> System.Xml[0x799be73480]: 5 09-30 14:49:52.918 D/Mono ( 1085): Loading reference 2 of System.Runtime.Serialization.dll asmctx DEFAULT, looking for System.ServiceModel.Internals, Version=0.0.0.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:52.920 D/Mono ( 1085): Image addref System.ServiceModel.Internals[0x7937f9df00] (asmctx DEFAULT) -> System.ServiceModel.Internals.dll[0x7935889800]: 2 09-30 14:49:52.920 D/Mono ( 1085): Prepared to set up assembly 'System.ServiceModel.Internals' (System.ServiceModel.Internals.dll) 09-30 14:49:52.920 D/Mono ( 1085): Assembly System.ServiceModel.Internals[0x7937f9df00] added to domain RootDomain, ref_count=1 09-30 14:49:52.922 D/Mono ( 1085): AOT: image 'System.ServiceModel.Internals.dll.so' not found: dlopen failed: library "System.ServiceModel.Internals.dll.so" not found 09-30 14:49:52.923 D/Mono ( 1085): AOT: image '/Users/builder/jenkins/workspace/archive-mono/2019-06/android/release/sdks/out/android-arm64-v8a-release/lib/mono/aot-cache/arm64/System.ServiceModel.Internals.dll.so' not found: (null) 09-30 14:49:52.923 D/Mono ( 1085): Config attempting to parse: 'System.ServiceModel.Internals.dll.config'. 09-30 14:49:52.923 D/Mono ( 1085): Config attempting to parse: '/Users/builder/jenkins/workspace/archive-mono/2019-06/android/release/sdks/out/android-arm64-v8a-release/etc/mono/assemblies/System.ServiceModel.Internals/System.ServiceModel.Internals.config'. 09-30 14:49:52.923 D/Mono ( 1085): Assembly Ref addref System.Runtime.Serialization[0x7935aa8d00] -> System.ServiceModel.Internals[0x7937f9df00]: 2 09-30 14:49:52.923 D/Mono ( 1085): Loading reference 0 of System.ServiceModel.Internals.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:52.923 D/Mono ( 1085): Assembly Ref addref System.ServiceModel.Internals[0x7937f9df00] -> mscorlib[0x7a3039be80]: 64 09-30 14:49:52.923 D/Mono ( 1085): Loading reference 2 of System.ServiceModel.Internals.dll asmctx DEFAULT, looking for System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:52.924 D/Mono ( 1085): Assembly Ref addref System.ServiceModel.Internals[0x7937f9df00] -> System.Xml[0x799be73480]: 6 Loaded assembly: System.ServiceModel.Internals.dll [External]09-30 14:49:52.924 D/Mono ( 1085): Loading reference 3 of System.Runtime.Serialization.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:52.924 D/Mono ( 1085): Assembly Ref addref System.Runtime.Serialization[0x7935aa8d00] -> System[0x799acd1580]: 10 09-30 14:49:52.998 D/Mono ( 1085): Loading reference 1 of System.Xml.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:52.999 D/Mono ( 1085): Assembly Ref addref System.Xml[0x799be73480] -> System[0x799acd1580]: 11 09-30 14:49:53.099 D/Mono ( 1085): Loading reference 1 of System.ServiceModel.Internals.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:53.100 D/Mono ( 1085): Assembly Ref addref System.ServiceModel.Internals[0x7937f9df00] -> System[0x799acd1580]: 12 09-30 14:49:53.145 D/Mono ( 1085): Loading reference 19 of /storage/emulated/0/Android/data/com.companyname.agentconnectmobile/files/.__override__/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=abc123 09-30 14:49:53.146 D/Mono ( 1085): Assembly Ref addref Xamarin.Forms.Platform.Android[0x799acc0e00] -> System.Xml[0x799be73480]: 7 09-30 14:49:53.221 D/Mono ( 1085): DllImport searching in: 'libmono-native.so' ('./libmono-native.so'). 09-30 14:49:53.221 D/Mono ( 1085): Searching for 'SystemNative_Unlink'. 09-30 14:49:53.221 D/Mono ( 1085): Probing 'SystemNative_Unlink'. 09-30 14:49:53.222 D/Mono ( 1085): Found as 'SystemNative_Unlink'. 09-30 14:49:53.279 D/Mono ( 1085): DllImport searching in: 'libmono-native.so' ('./libmono-native.so'). 09-30 14:49:53.279 D/Mono ( 1085): Searching for 'SystemNative_LStat2'. 09-30 14:49:53.279 D/Mono ( 1085): Probing 'SystemNative_LStat2'. 09-30 14:49:53.279 D/Mono ( 1085): Found as 'SystemNative_LStat2'. 09-30 14:49:53.279 D/Mono ( 1085): DllImport searching in: 'libmono-native.so' ('./libmono-native.so'). 09-30 14:49:53.279 D/Mono ( 1085): Searching for 'SystemNative_Rename'. 09-30 14:49:53.279 D/Mono ( 1085): Probing 'SystemNative_Rename'. 09-30 14:49:53.280 D/Mono ( 1085): Found as 'SystemNative_Rename'. 09-30 14:49:53.553 D/Mono ( 1085): DllImport searching in: 'libmono-native.so' ('./libmono-native.so'). 09-30 14:49:53.553 D/Mono ( 1085): Searching for 'SystemNative_Link'. 09-30 14:49:53.553 D/Mono ( 1085): Probing 'SystemNative_Link'. 09-30 14:49:53.553 D/Mono ( 1085): Found as 'SystemNative_Link'. 09-30 14:49:53.563 D/Mono ( 1085): DllImport searching in: 'libmono-native.so' ('./libmono-native.so'). 09-30 14:49:53.563 D/Mono ( 1085): Searching for 'SystemNative_Stat2'. 09-30 14:49:53.563 D/Mono ( 1085): Probing 'SystemNative_Stat2'. 09-30 14:49:53.563 D/Mono ( 1085): Found as 'SystemNative_Stat2'. 09-30 14:49:53.564 D/Mono ( 1085): DllImport searching in: 'libmono-native.so' ('./libmono-native.so'). 09-30 14:49:53.564 D/Mono ( 1085): Searching for 'SystemNative_Symlink'. 09-30 14:49:53.564 D/Mono ( 1085): Probing 'SystemNative_Symlink'. 09-30 14:49:53.564 D/Mono ( 1085): Found as 'SystemNative_Symlink'. 09-30 14:49:53.588 W/com.companyname.agentconnectmobile( 1085): type=1400 audit(0.0:4414): avc: denied { link } for comm=54687265616420506F6F6C20576F72 name="PropertyStore.forms.tmp" dev="dm-6" ino=77573 scontext=u:r:untrusted_app_27:s0:c6,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c6,c257,c512,c768 tclass=file permissive=0 09-30 14:49:53.597 D/Mono ( 1085): DllImport searching in: 'libmono-native.so' ('./libmono-native.so'). 09-30 14:49:53.598 D/Mono ( 1085): Searching for 'SystemNative_CopyFile'. 09-30 14:49:53.598 D/Mono ( 1085): Probing 'SystemNative_CopyFile'. 09-30 14:49:53.598 D/Mono ( 1085): Found as 'SystemNative_CopyFile'. **System.NullReferenceException:** 'Object reference not set to an instance of an object.'
This is my first Xamarin application so I'm not sure if I am supposed to be handling exit on Android somehow? I haven't seen this issue on iOS.
Answers
If you click the back button to exit the apllcation in android, It means that you close this application, not make the application to the background.
I think when you see the following log, it means that your application is closed. I think that you do not need to handle the
**System.NullReferenceException:** 'Object reference not set to an instance of an obj
I have same issue but don't have enough time to deal with it.
What concrete steps we can do to avoid this problem?
It is a big bad bug. I can't deploy with Form 4.2 as it is a show stopper.
https://github.com/xamarin/Xamarin.Forms/issues/7327
Good try, but this workaround closes application completely. Standard behavior just put it to sleep.