调用Device.RuntimePlatform会导致运行时异常

台电

我已将我所有项目(平台+共享)中的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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

修改UI后调用Thread.sleep()似乎会导致运行时错误

push :: device_vector.pushback()会导致对memcpy的调用吗?

不能调用或构造名称空间样式的导入,并且将在运行时导致失败

调用callback()到Java时应用崩溃。由于detatchThread而导致运行时错误

C++ 纯虚函数调用不会抛出运行时异常?

在运行时执行带有已检查异常的方法调用而不捕获它的行为

客房持久性库调用间inMemoryBuilder方法时,运行时异常

运行时错误脚本目标的调用目标抛出了异常。

运行时异常无法在未调用looper.prepare错误的线程内创建处理程序

托管的 .NET Core 运行时中的托管代码会破坏调用者堆栈

从x到y的协变量数组转换可能会导致运行时异常

变量 'loginusername' 在被赋值之前使用。运行时可能会导致空引用异常

运行时未调用权限

未调用运行时的正确函数

在运行时调用macroexpand

为什么在函数 B 中调用函数 A 而不是在函数 C 中调用函数 B 会破坏 go 运行时

在运行时加载PHP扩展会导致未捕获的错误:调用未定义的函数dl()

改变PySide.QtGui.QListWidget与从multiprocessing.Pool异步调用发出信号导致运行时错误?

Luasocket + Nginx错误-Lua入口线程异常终止:运行时错误:尝试越过C调用边界

为什么在向量中的shared_ptr上调用方法会引发运行时异常?

警告变量“csCryptoStream”在被赋值之前被使用。运行时可能会导致空引用异常

Proguard导致Android导航组件出现运行时异常

空指针异常导致运行时错误

SQLite连接类中的函数导致运行时异常

未在代码中调用的函数在运行时被调用

使用Material Button会导致ClassNotFound运行时错误

循环中的Getpivotdata会导致运行时错误1004

删除注释会导致运行时崩溃吗?

插入公式会导致运行时错误1004