Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.Maui.Platform.HandlerNotFoundException: 'Handler not found for view BarcodeScanning.CameraView.' #102

Open
Makayla-Forsyth opened this issue Oct 16, 2024 · 1 comment

Comments

@Makayla-Forsyth
Copy link

Makayla-Forsyth commented Oct 16, 2024

Sorry of this is the wrong place to get help but I have no idea where else to post.

I keep getting this error when trying to set up a simple scanner. It happens after the OnAppearing method has run. Investigating further down it seems the Handler == null.

Trying to run it on a Pixel 5 Android Emulator with API 34. Running on Maui version 8.0.92 targeting net8.0-ios and net8.0-android34.0 (Haven't bothered testing on iOS yet as it's not as important). Running version 1.5.8 of BarcodeScanning.Native.Maui.

using BarcodeScanning;
using CommunityToolkit.Maui.Alerts;

namespace App.Views;

public partial class ScanPage : ContentPage
{
    public ScanPage()
    {
        try
        {
            InitializeComponent();

        }
        catch (Exception e)
        {

            throw;
        }
    }

    protected override async void OnAppearing()
    {
        try
        {
            await Methods.AskForRequiredPermissionAsync();
            base.OnAppearing();
            scanner.CameraEnabled = true;
            var test = scanner;

        }
        catch (Exception e)
        {

            throw;
        }
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="App.Views.ScanPage"
             xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:scanner="clr-namespace:BarcodeScanning;assembly=BarcodeScanning.Native.Maui"
             x:Name="QRCodeContent"
             Title="Scan QR Code">
    <Grid HorizontalOptions="Fill">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <scanner:CameraView x:Name="scanner"
                            CameraFacing="Back"
                            CaptureQuality="High"
                            CameraEnabled="False"
                            BarcodeSymbologies="All"
                            OnDetectionFinished="CameraView_OnDetectionFinished"
                            TapToFocusEnabled="True" />
    </Grid>

</ContentPage>
@afriscic
Copy link
Owner

Hello.
To me it looks like a Handler issue. If your page doesn't get disposed (it handles like a Singleton) when you close or navigate from it then don't call DisposeHandler method as you'll get into the issue that you describe.
On the other hand if your page gets disposed (like a Transient) the it is best to call DisposeHandler to prevent memory lekas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants