RadekVyM / SimpleToolkit

SimpleToolkit is a .NET MAUI library of helpers and simple, fully customizable controls, such as SimpleShell - custom Shell implementation that allows you to create unique navigation experiences.
MIT License
425 stars 41 forks source link

Can not use Simple Shell "Unable to cast object of type 'Microsoft.Maui.Controls.Handlers.ShellItemHandler' to type 'SimpleToolkit.SimpleShell.Handlers.SimpleShellItemHandler" #36

Open BeepBeepBopBop opened 9 months ago

BeepBeepBopBop commented 9 months ago

Hi I wanted to try the toolkit but unfortunately I am getting an error whenever I launch my app on Windows:

{"Unable to cast object of type 'Microsoft.Maui.Controls.Handlers.ShellItemHandler' to type 'SimpleToolkit.SimpleShell.Handlers.SimpleShellItemHandler'."}

What I did was to simply follow the Sample and I tried to track down my issue for the last couple hours without success.

I stripped my shell to the most basic possible and it looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<simpleShell:SimpleShell
    x:Class="BoxingTimer.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:BoxingTimer"
    xmlns:simpleShell="clr-namespace:SimpleToolkit.SimpleShell;assembly=SimpleToolkit.SimpleShell"
    x:Name="thisShell">

    <ShellContent
        Title="Home"
        ContentTemplate="{DataTemplate local:HomePage}"
        Route="MainPage" />

</simpleShell:SimpleShell>

I did include .UseSimpleShell() .UseSimpleToolkit()

Maybe you can help me troubleshooting this, I have tried with a new .NET8 application and it worked fine though

Full stack trace:

at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.CreateShellItemHandler() at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.SwitchShellItem(ShellItem newItem, Boolean animate) at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.MapCurrentItem(SimpleShellHandler handler, ISimpleShell shell) at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0.<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property) at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property) at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.MapContent(SimpleShellHandler handler, ISimpleShell shell) at Microsoft.Maui.PropertyMapper2.<>cDisplayClass5_0.b0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler2.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) at Microsoft.Maui.PropertyMapper`2.<>cDisplayClass5_0.b0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.SetHandler(IWinRTObject nativeElement, IElement element, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Window platformWindow, IWindow window, IMauiContext context) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, OpenWindowRequest args) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, LaunchActivatedEventArgs args) at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args) at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args) at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

RadekVyM commented 9 months ago

Hi @BeepBeepBopBop,

do you use any other library or your own ShellItem handler implementation in your project? I have no idea what could have caused the exception.