0

Sometimes an exception is thrown from inside the Xamarin.Forms external library and it would be extremely helpful to view the pertinent local variables in the debugger as we would in our own code.

Here is the stacktrace of my current Android iOS project headache:

System.InvalidCastException: Specified cast is not valid.

    at Xamarin.Forms.BindableLayoutController.CreateItemView (System.Object item, Xamarin.Forms.DataTemplate dataTemplate) [0x00003] in D:\a\1\s\Xamarin.Forms.Core\BindableLayout.cs:261   

    at Xamarin.Forms.BindableLayoutController.CreateItemView (System.Object item, Xamarin.Forms.Layout`1[T] layout) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableLayout.cs:254

    at Xamarin.Forms.BindableLayoutController.CreateChildren () [0x00040] in D:\a\1\s\Xamarin.Forms.Core\BindableLayout.cs:234

    at Xamarin.Forms.BindableLayoutController.SetItemTemplate (Xamarin.Forms.DataTemplate itemTemplate) [0x0005a] in D:\a\1\s\Xamarin.Forms.Core\BindableLayout.cs:180

    at Xamarin.Forms.BindableLayoutController.set_ItemTemplate (Xamarin.Forms.DataTemplate value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableLayout.cs:127

    at Xamarin.Forms.BindableLayout+<>c.<.cctor>b__19_1 (Xamarin.Forms.BindableObject b, System.Object o, System.Object n) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableLayout.cs:16

    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) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:463

    at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397

    at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:334

    at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:311

    at Xamarin.Forms.BindableLayout.SetItemTemplate (Xamarin.Forms.BindableObject b, Xamarin.Forms.DataTemplate value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableLayout.cs:45

    at SecretProjectName.Views.YourAmazingClassPage..ctor () [0x0005b] in C:\Users\UserName\source\repos\SecretProjectName\SecretProjectName\SecretProjectName\Views\YourAmazingClassPage.xaml.cs:20

    at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)

    at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:936

Is there any other way to do this than forking Xamarin.Forms source code into my project?

  • Full XF source code is avaliable on [Github](https://github.com/xamarin/Xamarin.Forms), but imho you can also check the API from [ms docs](https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms?view=xamarin-forms) to solve the issue. Or just post your code here is an alternative option. – Shaw Nov 15 '20 at 22:49
  • I really need to see the locals to debug this casting issue so I'm currently building XF from source inside my project. – Matthew Fairleaf Nov 15 '20 at 23:01
  • 1
    Building XF inside the project turns out to be really hard. – Matthew Fairleaf Nov 20 '20 at 20:27
  • Try to [create a minimal, reproducible sample](https://stackoverflow.com/help/minimal-reproducible-example) here. – Mr Qian Nov 23 '20 at 07:57

1 Answers1

1

DLLs are always compiled, thus you can't step in. They don't contain your (or someone elses) code in its source, it is modified by the process of compilation.

Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57