System.TypeLoadException: 'VTable setup of type AndroidX.AppCompat.View.Menu.MenuItemImpl failed'
System.TypeLoadException: 'VTable setup of type AndroidX.AppCompat.View.Menu.MenuItemImpl failed'
我正在尝试将 Xamarin Android 应用程序升级到 AndroidX。我完成了迁移过程并且项目构建没有错误,但在运行时我遇到了 IMenu
的问题。我有一个 activity 调用 OnCreateOptionsMenu(IMenu menu)
,当它到达 menu.FindItem
时,System.TypeLoadException: 'VTable setup of type AndroidX.AppCompat.View.Menu.MenuItemImpl failed'
被抛出。
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.common_menu, menu);
menu.FindItem(Resource.Id.action_settings).SetVisible(false); // Exception happens here.
return true;
}
堆栈跟踪:
at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x0002c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:951
at System.Reflection.RuntimeConstructorInfo.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00086] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:926
at System.Reflection.RuntimeConstructorInfo.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:960
at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Reflection/ConstructorInfo.cs:22
at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x0001b] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x00023] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at AndroidX.AppCompat.View.Menu.MenuBuilder.FindItem (System.Int32 id) [0x00036] in <c5220b8e1f564a28bc774e534daebefd>:0
at NatureMapr.Mobile.Droid.Activities.BaseActivity.OnCreateOptionsMenu (Android.Views.IMenu menu) [0x00013] in C:\Projects\NatureMapr\NatureMapr.Mobile.Droid\Activities\BaseActivity.cs:73
at Android.App.Activity.n_OnCreateOptionsMenu_Landroid_view_Menu_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_menu) [0x0000f] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,intptr)
如果能帮助我找到问题,我将不胜感激。
对于其他 运行 遇到此错误的人来说,这似乎是一个或多个 1.0.0-preview02 Xamarin AndroidX NuGet 包的问题。升级到 1.0.0.2 包已经解决了我的问题。
确保 Xamarin.AndroidX.AppCompact
是 installed/updated
您可以 install/update 使用 NuGet 包管理器
我可以通过将 Xamarin.AndroidX.ConstraintLayout 从版本 2.1.1.2 降级到 1.1.3.2 来解决这个错误。
我正在尝试将 Xamarin Android 应用程序升级到 AndroidX。我完成了迁移过程并且项目构建没有错误,但在运行时我遇到了 IMenu
的问题。我有一个 activity 调用 OnCreateOptionsMenu(IMenu menu)
,当它到达 menu.FindItem
时,System.TypeLoadException: 'VTable setup of type AndroidX.AppCompat.View.Menu.MenuItemImpl failed'
被抛出。
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.common_menu, menu);
menu.FindItem(Resource.Id.action_settings).SetVisible(false); // Exception happens here.
return true;
}
堆栈跟踪:
at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x0002c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:951
at System.Reflection.RuntimeConstructorInfo.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00086] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:926
at System.Reflection.RuntimeConstructorInfo.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:960
at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Reflection/ConstructorInfo.cs:22
at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x0001b] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x00023] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at AndroidX.AppCompat.View.Menu.MenuBuilder.FindItem (System.Int32 id) [0x00036] in <c5220b8e1f564a28bc774e534daebefd>:0
at NatureMapr.Mobile.Droid.Activities.BaseActivity.OnCreateOptionsMenu (Android.Views.IMenu menu) [0x00013] in C:\Projects\NatureMapr\NatureMapr.Mobile.Droid\Activities\BaseActivity.cs:73
at Android.App.Activity.n_OnCreateOptionsMenu_Landroid_view_Menu_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_menu) [0x0000f] in <7d2292394f8c488b97f5bc2a0ac0240d>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,intptr)
如果能帮助我找到问题,我将不胜感激。
对于其他 运行 遇到此错误的人来说,这似乎是一个或多个 1.0.0-preview02 Xamarin AndroidX NuGet 包的问题。升级到 1.0.0.2 包已经解决了我的问题。
确保 Xamarin.AndroidX.AppCompact
是 installed/updated
您可以 install/update 使用 NuGet 包管理器
我可以通过将 Xamarin.AndroidX.ConstraintLayout 从版本 2.1.1.2 降级到 1.1.3.2 来解决这个错误。