Xamarin Android Update Causes System.Reflection.TargetInvocationException

I was prompted to update Visual Studio 2019 and it appears the updates broke my Xamarin.Forms app. The same error began occurring on OSX after the update on the 29th. Windows was fine until I updated today.

The app was running just fine right before I updated, now I receive a System.Reflection.TargetInvocationException when it hits base.OnBindingContextChanged(). On debugging it doesn't let me dig any further, it just throws the exception.

Here is the full stacktrace:

{System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.BadImageFormatException: Cannot box IsByRefLike type 'System.ReadOnlySpan`1'
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <ff07eae8184a40a08e79049bbcb31a0e>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00086] in <ff07eae8184a40a08e79049bbcb31a0e>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <ff07eae8184a40a08e79049bbcb31a0e>:0 
  at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1[TResult] getConverter, System.IServiceProvider serviceProvider) [0x002f8] in D:\agent\_work\1\s\Xamarin.Forms.Core\Xaml\TypeConversionExtensions.cs:180 
  at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1[TResult] minfoRetriever, System.IServiceProvider serviceProvider) [0x00021] in D:\agent\_work\1\s\Xamarin.Forms.Core\Xaml\TypeConversionExtensions.cs:76 
  at Xamarin.Forms.Xaml.ValueConverterProvider.Convert (System.Object value, System.Type toType, System.Func`1[TResult] minfoRetriever, System.IServiceProvider serviceProvider) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\Xaml\ValueConverterProvider.cs:14 
  at Xamarin.Forms.BindingCondition.EqualsToValue (System.Object other) [0x00025] in D:\agent\_work\1\s\Xamarin.Forms.Core\Interactivity\BindingCondition.cs:79 
  at Xamarin.Forms.BindingCondition.OnBoundPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\Interactivity\BindingCondition.cs:88 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x0011b] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:597 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:391 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:174 
  at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:77 
  at Xamarin.Forms.Binding.Apply (System.Object newContext, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty) [0x00042] in D:\agent\_work\1\s\Xamarin.Forms.Core\Binding.cs:126 
  at Xamarin.Forms.BindableObject.ApplyBindings (System.Boolean skipBindingContext) [0x0003b] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:422 
  at Xamarin.Forms.BindableObject.ApplyBindings () [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:126 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x0005a] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:120 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:511 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:354 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in D:\agent\_work\1\s\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x00060] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:121 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:511 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:354 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in D:\agent\_work\1\s\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x00060] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:121 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:511 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:354 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in D:\agent\_work\1\s\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.Grid.OnBindingContextChanged () [0x00006] in D:\agent\_work\1\s\Xamarin.Forms.Core\Grid.cs:147 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x00060] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:121 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:511 
  at Xamarin.Forms.TemplatedView.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00008] in D:\agent\_work\1\s\Xamarin.Forms.Core\TemplatedView.cs:65 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:354 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in D:\agent\_work\1\s\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.ContentView.OnBindingContextChanged () [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\ContentView.cs:16 
  at AVP.H53.Controls.NavBar.OnBindingContextChanged () [0x0001a] in D:\projects\AVP\avp-h53\H53\AVP.H53\Controls\NavBar.xaml.cs:68 
  at Xamarin.Forms.BindableObject.BindingContextPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x0000e] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:442 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x0011b] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:597 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:391 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:174 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:56 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:551 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in /Users/builder/jenkins/workspace/xamarin-android-commercial/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/jenkins/workspace/xamarin-android-commercial/xamarin-android/src/Mono.Android/obj/Release/android-24/mcw/Java.Lang.IRunnable.cs:81 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.6(intptr,intptr)} 

Has anyone encountered this or can suggest a solution?

OSX and Windows both have:

  • Xamarin 16.2.0.91
  • Xamarin.Android SDK 9.4.1.0

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    If you update the new version, please do not run your project in previous emulator or device, you can recreate a new emulator, then run your project. Before you run your project, please clean the solution and re-build it.

  • JimmyMcDermottJimmyMcDermott USMember

    Thanks Leon, unfortunately that still didn't work.

Sign In or Register to comment.