[退出应用后,在Android的Xamarin.Forms中获取NullReferenceException

问题描述 投票:0回答:1

我正在使用Xamarin Forms 4.2.0,并使用Xamarin.Forms Shell。在应用程序的各个屏幕之间导航时,按返回按钮似乎可以正常工作,但是,当我在调试时按返回退出应用程序时,会收到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.'

这是我的第一个Xamarin应用程序,因此我不确定是否应该以某种方式处理Android上的退出?我在iOS上没有看到此问题。

xamarin xamarin.forms xamarin.android
1个回答
0
投票

有一个类似的问题,现在的问题似乎是Shell将空页推入4.2.xxx及更高版本的NavStack中,这很烦人,但这就是事实。通过在Apps Shell类的OnBackButtonPressed中编写以下代码,我能够解决此问题。

    protected override bool OnBackButtonPressed()
    {
        if (Application.Current.MainPage.GetType() == typeof(AppShell) && Shell.Current.Navigation.NavigationStack.Where(x => x != null).Any())
        {
            return base.OnBackButtonPressed();
        }
        else
        {
            System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
            return true;
        }
    } 

AppShell是我的自定义Shell类。

© www.soinside.com 2019 - 2024. All rights reserved.