Skip to content

Changing <DataTemplate/> contents can give a runtime exception #11203

Closed

Description

@jonathanpeppers

Description

I was testing this app: https://github.com/ionixjunior/YellowClone/tree/migracao_maui/YellowClone

In MyTripsView.xaml, if you comment out the <ViewCell/>:

image

In this case, I was going to type a new <TextCell Text="{Binding Name}" />, but it hit this issue before I was able to.

If I run the app with an empty <DataTemplate/>, it runs fine. Then I'm able to add a new <TextCell/> or <ViewCell/> and hot reload them. It only fails when you remove a working cell.

Full stack trace is:

System.InvalidCastException
  Message=Specified cast is not valid.
 	0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception	C#
 	0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5	C#
 	0x26 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:430,26	C#
 	0x39 in Android.Runtime.DynamicMethodNameCounter.21	C#
 	0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x74 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:12320,4	C#
 	0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6	C#
 	0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5	C#
 	0x1F in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.ListView>.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Android\VisualElementRenderer.cs:54,6	C#
 	0x8 in Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ListViewRenderer.cs:298,4	C#
 	0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,4	C#
 	0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:429,5	C#
 	0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x74 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:12320,4	C#
 	0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6	C#
 	0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5	C#
 	0xD4 in Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler at D:\a\_work\1\s\src\Core\src\Handlers\ViewHandlerExtensions.Android.cs:131,4	C#
 	0x2 in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.ListView>.Microsoft.Maui.IViewHandler.PlatformArrange at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\VisualElementRenderer.cs:230,4	C#
 	0x1F in Microsoft.Maui.Controls.VisualElement.ArrangeOverride at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:124,4	C#
 	0x2 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:116,4	C#
 	0x5A in Microsoft.Maui.Layouts.LayoutExtensions.ArrangeContent at D:\a\_work\1\s\src\Core\src\Layouts\LayoutExtensions.cs:174,4	C#
 	0x9 in Microsoft.Maui.Controls.ContentPage.Microsoft.Maui.IContentView.CrossPlatformArrange at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\ContentPage.Impl.cs:35,4	C#
 	0x22 in Microsoft.Maui.Platform.ContentViewGroup.OnLayout at D:\a\_work\1\s\src\Core\src\Platform\Android\ContentViewGroup.cs:92,4	C#
 	0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,4	C#
 	0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:429,5	C#

(sorry VS copied this funny)

Steps to Reproduce

  1. Run YellowClone (change to net7.0 if you want latest MAUI version)
  2. Click the hamburger menu and go to My Trips
  3. Comment out the <ViewCell/>

Link to public reproduction project repository

https://github.com/ionixjunior/YellowClone/tree/migracao_maui/YellowClone

Version with bug

7.0 Release Candidate 2

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

all

Did you find any workaround?

Rebuild the app, not using XAML hot reload.

Relevant log output

No response

Activity

  1. added
    t/bug
    partner/hot-reload-xaml
    on Nov 8, 2022
  2. rachelkang commented on Nov 8, 2022

    @rachelkang
    Member

    @drasticactions thoughts on this one?

  3. added this to the Backlog milestone on Nov 8, 2022
  4. drasticactions commented on Nov 8, 2022

    @drasticactions
    Contributor

    I believe this was a Xamarin.Forms bug as well since the code is similar (if not the same).

    The stack error is accurate, the specific cast is not valid. Having an empty template when it launches works by luck because it doesn't go down the paths to cast unless it has already been set.

    ListViewBug.zip

    You can directly replicate this bug without XAML Hot Reload by dynamically setting a ListView with a new data template.

  5. added a commit that references this issue on Feb 7, 2023
    9ab7067
  6. added
    fixed-in-8.0.0-preview.1.7762
    on Feb 23, 2023
  7. ghost locked as resolved and limited conversation to collaborators on Mar 25, 2023
  8. modified the milestones: Backlog, 8.0-preview1 on Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

fixed-in-8.0.0-preview.1.7762partner/hot-reload-xamlplatform/androidplatform/windowst/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions