[Android] RendererToHandlerShim found for Custom ShellRenderer is Incompatible
See original GitHub issueDescription
I am trying to provide a simplistic ShellRenderer possible via MauiAppBuilder.AddCompatibilityRenderer. When the Shell attempts to render a ToPlatformException is thrown with the following message: ‘Microsoft.Maui.Controls.Compatibility.RendererToHandlerShim found for MauiApp2.AppShell is incompatible’
My goal is to make my Android app function more like the iOS variant. Within Shell on the iOS build, when a tabs navigation stack is several layers deep, you can tap the tabs icon in order to quickly return to the root page. On Android tapping the tab icon does nothing.
It appears that by providing my own ShellRenderer and ShellItemRenderer on Android I could override the OnTabReselected function in order to provide the functionality I am looking for. (Ref: Similar Xamarin Issue)
Repro Project: Repro.zip
Steps to Reproduce
- Start with the default MAUI project template.
- Add a custom ShellRenderer
- Assign the custom ShellRenderer using MauiAppBuilder.AddCompatibilityRenderer
- Run the app on an Android device and the exception should occur.
Version with bug
6.0 Release Candidate 3
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 10
Did you find any workaround?
No, but open to ideas/suggestions if there are other ways to achieve the desired behavior.
Relevant log output
Microsoft.Maui.Platform.ToPlatformException
Message=Microsoft.Maui.Controls.Compatibility.RendererToHandlerShim found for MauiApp2.AppShell is incompatible
Source=Microsoft.Maui
StackTrace:
at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 113
at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 142
at Microsoft.Maui.Platform.ContainerView.SetView(IElement view, Boolean forceRefresh) in D:\a\_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:line 72
at Microsoft.Maui.Platform.ContainerView.set_CurrentView(IElement value) in D:\a\_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:line 51
at Microsoft.Maui.Platform.ElementExtensions.ToContainerView(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\Android\ElementExtensions.cs:line 11
at Microsoft.Maui.Platform.NavigationRootManager.Connect(IView view, IMauiContext mauiContext) in D:\a\_work\1\s\src\Core\src\Platform\Android\Navigation\NavigationRootManager.cs:line 49
at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) in D:\a\_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:line 17
at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 183
at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 47
at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 82
at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:line 74
at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:line 64
at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:line 20
at Microsoft.Maui.Platform.ElementExtensions.SetHandler(Context nativeElement, IElement element, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 171
at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Activity platformWindow, IWindow window, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 181
at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Activity activity, IApplication application, Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\ApplicationExtensions.cs:line 46
at Microsoft.Maui.MauiAppCompatActivity.OnCreate(Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.cs:line 32
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-32/mcw/Android.App.Activity.cs:line 2781
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 121
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top GitHub Comments
@jcsnider Use this code to register your shell custom renderer.
A was getting the System.InvalidCastException: 'Specified cast is not valid renderer exception. The problem was because I was using AddCompatibilityRenderer instead of AddHandler. Thanks a lot, guys!