我已将我所有项目(平台+共享)中的Xamarin.Forms软件包更新为最新版本(2.3.4.224),现在看来不应该再使用它,Device.OS
也不应该TargetPlatform
枚举它们,因为它们已经过时了。
编译器抱怨这些行:
if (Device.OS == TargetPlatform.iOS)
_API_BASE_URI = "http://XXX.XXX.XXX.XXX";
else
_API_BASE_URI = "http://YYY.YYY.YYY.YYY";
它说:
“ Device.OS已过时。请改为使用RuntimePlatform”
到目前为止,到目前为止,我想修复此问题,并且一直在尝试使用:
Debug.WriteLine(Device.RuntimePlatform);
但这会引发运行时异常。这是堆栈跟踪
04-08 14:57:34.812 I / MonoDroid(3782):未处理的例外:04-08 14:57:34.824 I / MonoDroid(3782):System.TypeInitializationException:'Mob.ApiCommunication'的类型初始值设定项引发了异常。---> System.MissingMethodException:找不到方法'Xamarin.Forms.Device.get_RuntimePlatform'。04-08 14:57:34.824 I / MonoDroid(3782):-内部异常堆栈跟踪结束--- 04-08 14:57:34.824 I / MonoDroid(3782):at(wrappermanaged-to-native )System.Object:__ icall_wrapper_mono_generic_class_init(intptr)04-08 14:57:34.824 I / MonoDroid(3782):at Mob.Views.Public.LoginViewModel.RestoreState(System.Collections.Generic.IDictionary`2 [TKey,TValue]词典)[0x00001] in C:\ Users ... \ Source ... \ LoginViewModel.cs:52 04-08 14:57:34.824 I / MonoDroid(3782):at Mob.App.OnStart()[0x00001] in C:\ Users ... \ App.xaml.cs:39 04-08 14:57:34.824 I / MonoDroid(3782):位于C:\ BuildAgent2 \ work中的Xamarin.Forms.Application.SendStart()[0x00000] \ ca3766cfc22354a1 \ Xamarin.Forms.Core \ Application.cs:228 04-08 14:57:34.824 I / MonoDroid(3782):位于Xamarin.Forms.Platform.Android.FormsAppCompatActivity + d__43.MoveNext()[0x0003b]在C中:\ BuildAgent2 \ work \ ca3766cfc22354a1 \ Xamarin.Forms.Platform.Android \ AppCompat \ FormsAppCompatActivity.cs:426 04-08 14:57:34.824 I / MonoDroid(3782):-从上次发生异常的位置开始的堆栈跟踪结束抛出--- 04-08 14:57:34.824 I / MonoDroid(3782):在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000c]在/ Users / builder / data / lanes / 4468 / f913a78a / source / mono / mcs / class / referencesource / mscorlib / system / runtime / exceptionservices / exceptionservicescommon.cs:143 04-08 14:57:34.824 I / MonoDroid(3782):位于System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0(System.Object状态)[0x00000]在/Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 04-08 14:57:34.824 I / MonoDroid(3782):在Android.App.SyncContext + c__AnonStorey0。<> /Users/builder/data/lanes/4468/b16fb820/source/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:35 04-08 14:57:34.824中的> m__0()[0x00000] I / MonoDroid(3782):位于/Users/builder/data/lanes/4468/b16fb820/source/xamarin-android/src/Mono.Android/Java中的Java.Lang.Thread + RunnableImplementor.Run()[0x0000b]。 Lang / Thread.cs:36 04-08 14:57:34.824 I / MonoDroid(3782):在Java.Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv,System.IntPtr native__this)[0x00009]在/ Users / builder /数据/通道/ 4468 / b16fb820 /源/monodroid/src/Mono.Android/platforms/android-25/src/produced/Java.Lang.IRunnable.cs:81 04-08 14:57:34.824 I / MonoDroid(3782 ):在(包装器动态方法)System.Object:88db5e57-5ac7-4ba4-a574-4ec5eaf704fd(intptr,intptr)App / SyncContext.cs:35 04-08 14:57:34.824 I / MonoDroid(3782):位于/ Users / builder / data / lanes / 4468 / b16fb820中的Java.Lang.Thread + RunnableImplementor.Run()[0x0000b] /source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36 04-08 14:57:34.824 I / MonoDroid(3782):在Java.Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv ,/ Users / builder / data / lanes / 4468 / b16fb820 / source / monodroid / src / Mono.Android / platforms / android-25 / src / generation / Java.Lang.IRunnable.cs中的System.IntPtr native__this)[0x00009] :81 04-08 14:57:34.824 I / MonoDroid(3782):at(包装动态方法)System.Object:88db5e57-5ac7-4ba4-a574-4ec5eaf704fd(intptr,intptr)App / SyncContext.cs:35 04-08 14:57:34.824 I / MonoDroid(3782):位于/ Users / builder / data / lanes / 4468 / b16fb820中的Java.Lang.Thread + RunnableImplementor.Run()[0x0000b] /source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36 04-08 14:57:34.824 I / MonoDroid(3782):在Java.Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv ,/ Users / builder / data / lanes / 4468 / b16fb820 / source / monodroid / src / Mono.Android / platforms / android-25 / src / generation / Java.Lang.IRunnable.cs中的System.IntPtr native__this)[0x00009] :81 04-08 14:57:34.824 I / MonoDroid(3782):at(包装动态方法)System.Object:88db5e57-5ac7-4ba4-a574-4ec5eaf704fd(intptr,intptr)36 04-08 14:57:34.824 I / MonoDroid(3782):位于Java / Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv,System.IntPtr native__this)[0x00009]在/ Users / builder / data / lanes / 4468 / b16fb820 / source / monodroid / src / Mono.Android / platforms / android-25 / src / generation / Java.Lang.IRunnable.cs:81 04-08 14:57:34.824 I / MonoDroid(3782):at(包装动态-方法)System.Object:88db5e57-5ac7-4ba4-a574-4ec5eaf704fd(intptr,intptr)36 04-08 14:57:34.824 I / MonoDroid(3782):位于Java / Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv,System.IntPtr native__this)[0x00009]在/ Users / builder / data / lanes / 4468 / b16fb820 / source / monodroid / src / Mono.Android / platforms / android-25 / src / generation / Java.Lang.IRunnable.cs:81 04-08 14:57:34.824 I / MonoDroid(3782):at(包装动态-方法)System.Object:88db5e57-5ac7-4ba4-a574-4ec5eaf704fd(intptr,intptr)
我是否缺少使用RuntimePlatform的功能?我环顾四周,但是目前有关Device
该类的任何文档/示例都在使用不赞成使用的成员。
我想出了一个解决方案。奇怪的是,在发布SO之前,我已经为我的Xamarin项目做到了这一点,并且没有任何效果。但是这一次,阅读Xamarin论坛的主题后:https://forums.xamarin.com/discussion/92455/xamarin-forms-2-3-4-224这就是我所做的:
我已经关闭VisualStudio,从解决方案中的所有项目中清除了所有“ bin”和“ obj”文件夹,然后重新启动了VS,然后清理并重建了解决方案。
现在Debug.WriteLine(Device.RuntimePlatform);
按预期返回“ Android”字符串!,
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句