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

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.PancakeView.Droid.PancakeDrawable from native handle #158

Open
domenk opened this issue Jan 15, 2021 · 1 comment

Comments

@domenk
Copy link

domenk commented Jan 15, 2021

When using GradientStopCollection together with Background setter, in certain scenarios Android throws mentioned exception.

I was not able to trim down code for sharing, because it's called after a series of callbacks and skipping some of them makes issue go away.

Exception:

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.PancakeView.Droid.PancakeDrawable from native handle 0xbfb0fafc (key_handle 0x2f236dc9).
---> System.MissingMethodException: No constructor found for Xamarin.Forms.PancakeView.Droid.PancakeDrawable::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Unable to activate instance of type Xamarin.Forms.PancakeView.Droid.PancakeDrawable from native handle 0xbfb0fb1c (key_handle 0xf639376).
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017e] in <123>:0 
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x00023] in <123>:0 
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <123>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <123>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <123>:0 
  at Android.Graphics.Drawables.Drawable.n_GetOpacity (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <123>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.74(intptr,intptr)

(Visual Studio stops at base.OnElementPropertyChanged(sender, e); line in Droid.PancakeViewRenderer.OnElementPropertyChanged.)

Style that causes exception:

<Style x:Key="styleName" TargetType="pancake:PancakeView">
  <Setter Property="Background" Value="red" />
  <Setter Property="BackgroundGradientStartPoint" Value="0,0" />
  <Setter Property="BackgroundGradientEndPoint" Value="0,1" />
  <Setter Property="BackgroundGradientStops">
    <pancake:GradientStopCollection>
      <pancake:GradientStop Color="green" Offset="0" />
      <pancake:GradientStop Color="blue" Offset="1" />
    </pancake:GradientStopCollection>
  </Setter>
</Style>

Commenting out Background or BackgroundGradientStops setter resolves the issue.

Occurs on Xamarin.Forms 5.0.0.1874.

Maybe related: #113. Adding constructor public PancakeDrawable(IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer) { } and null-check for _pancake in Dispose method seems to resolve the issue.

@justintoth
Copy link

For me I ran into the same exception with PancakeView when dynamically setting the background color.

<cake:PancakeView.Triggers>
                <DataTrigger
                    Binding="{Binding IsPartialReceipt}"
                    TargetType="cake:PancakeView"
                    Value="True">
                    <Setter Property="BackgroundColor" Value="#FBF8ED" />
                </DataTrigger>
                <DataTrigger
                    Binding="{Binding IsPartialReceipt}"
                    TargetType="cake:PancakeView"
                    Value="False">
                    <Setter Property="BackgroundColor" Value="White" />
                </DataTrigger>
            </cake:PancakeView.Triggers>

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