Home > Enterprise >  Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.FrameRenderer
Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.FrameRenderer

Time:02-11

I am having a issue with a Android app when I click a button that talks to the webservice and then click another button I get this exception.

Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.FrameRenderer from native handle 0x7fcb566738 (key_handle 0x3ed634c).

The Exception appears to be coming from the following xaml

  <Frame x:Name="TileFrame" Margin="5" Grid.Column="0" Grid.Row="0"
           BindingContext="{x:Reference this}"
           effects:TouchEffect.Command="{Binding TapTile}"
           effects:TouchEffect.CommandParameter="{Binding}">
            <StackLayout VerticalOptions="Center">
  
                <Label
                    BindingContext="{x:Reference this}"
                    Text="{Binding Title}" 
                    FontSize="20"
                    LineHeight="1"
                    FontAttributes="Bold"
                    TextTransform="Uppercase"
                    HorizontalTextAlignment="Center"
                    Opacity="1"
                    Margin="5, 0" />
            </StackLayout>
        </Frame>

if I change the frame to a button I get the following exception

   <Button x:Name="TileFrame" Margin="5" Grid.Column="0" Grid.Row="0"
           BindingContext="{x:Reference this}"
           effects:TouchEffect.Command="{Binding TapTile}"
           effects:TouchEffect.CommandParameter="{Binding}">
            
        </Button>

Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer from native handle 0x7fcb55a1d8 (key_handle 0x46ac678).

I have found this on git hub but its from 2020 and I see to be having the same issue and so far the work arounds do not solve my issue

https://github.com/xamarin/Xamarin.Forms/issues/9136

CodePudding user response:

So after lots of digging. The app was doing things with the UI and not always on the UI thread. So wrapping the code in the following code it provided more stability for the app.

MainThread.BeginInvokeOnMainThread(() =>
{
    // Code to run on the main thread
});

https://docs.microsoft.com/en-us/xamarin/essentials/main-thread

  • Related