question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] RendererToHandlerShim found for Custom ShellRenderer is Incompatible

See original GitHub issue

Description

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

  1. Start with the default MAUI project template.
  2. Add a custom ShellRenderer
  3. Assign the custom ShellRenderer using MauiAppBuilder.AddCompatibilityRenderer
  4. 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:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
851265601commented, Jun 10, 2022

@jcsnider Use this code to register your shell custom renderer.

ConfigureMauiHandlers(handlers => {            
#if ANDROID
	handlers.AddHandler(typeof(Shell), typeof(CustomShellRenderer));
#endif

            });
1reaction
Higor13commented, Aug 10, 2022

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin.Forms Shell custom renderers
On Android, the ShellRenderer class can be found in the Xamarin.Forms.Platform.Android namespace. The process for creating a Shell custom ...
Read more >
Reuse custom renderers in .NET MAUI
Forms custom renderers, provided that the renderer derives from FrameRenderer , ListViewRenderer , ShellRenderer on iOS and Android, ...
Read more >
Custom Renderer causes crash of .Net MAUI app
The reason it's not working is because you need to add it with the compatibility Renderer method and not as handlers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found