.net maui error - how to track down handler not found error'

Viewed 86

I'm getting the error below, yet i think my xaml and .cs file are correct. Microsoft.Maui.Platform.HandlerNotFoundException: 'Handler not found for view ZXing.Net.Maui.Controls.CameraBarcodeReaderView.'

I think this means that the handler i have for my camerabarreaderview isn't found, but it appears to be there. Any idea what I am doing wrong? i'm hoping another set of eyes will be helpful. TIA

xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI"
             x:Class="ScanAndScoringMauiApp.Pages.ScanPage"
             Title="ScanPage">

    <Grid RowDefinitions="1*,3*,1*">

        <zxing:CameraBarcodeReaderView
            Grid.Row="0" Grid.RowSpan="3"
            x:Name="barcodeView"
            BarcodesDetected="barcodeView_BarcodesDetected"
             />

        <Grid
            Grid.Row="0"
            BackgroundColor="#aa000000">
            <Label Grid.Row="2" Text="Top text..." HorizontalOptions="Center" VerticalOptions="Center" TextColor="White" />
        </Grid>

        <Grid
            Grid.Row="3"
            BackgroundColor="#aa000000"
            Padding="20"
            ColumnDefinitions="Auto,*,Auto">

            <Button Text="️" Grid.Column="0" BackgroundColor="#aa000000" CornerRadius="8" BorderColor="Black" Clicked="Button_Clicked" />

            <zxing:BarcodeGeneratorView
                x:Name="barcodeGenerator"
                Grid.Column="1"
                HorizontalOptions="Center"
                VerticalOptions="Center"
                HeightRequest="100"
                WidthRequest="100"
                ForegroundColor="DarkBlue"
                Format="QrCode"
                Value="Bla"
                BarcodeMargin="1" />

            <Button Text="" Grid.Column="2" BackgroundColor="#aa000000" CornerRadius="8" BorderColor="Black" Clicked="Button_Clicked_1" />
        </Grid>

    </Grid>
</ContentPage>

my code file:

    namespace ScanAndScoringMauiApp.Pages;

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

private void Button_Clicked(object sender, EventArgs e)
{

}

private void Button_Clicked_1(object sender, EventArgs e)
{

}

private void barcodeView_BarcodesDetected(object sender, 
    ZXing.Net.Maui.BarcodeDetectionEventArgs e)
{

}
}
1 Answers

thanks to @toolmakersteve, i was able to search and find the answer. I had to make my mauiprogram.cs file look like this. boom, it all worked.

using ZXing.Net.Maui;

#if ANDROID
[assembly: Android.App.UsesPermission(Android.Manifest.Permission.Camera)]
#endif
namespace ScanAndScoringMauiApp;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>().UseBarcodeReader()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });

        return builder.Build();
    }
}
Related