0

While upgrading a Xamarin app that leverages Splat's bitmap functionality we are getting errors around the use of the methods mentioned in the title:

'IBitmap' does not contain a definition for 'ToNative' and no accessible extension method 'ToNative' accepting a first argument of type 'IBitmap' could be found (are you missing a using directive or an assembly reference?)

In an effort to troubleshoot the problem we have created a new sample Android-only Xamarin app and referenced Splat and Splat.Drawing via NuGet. We then added calls to these methods and have reproduced the error:

    public void Bar(IBitmap source)
    {
        Bitmap native = source.ToNative();
        IBitmap bitmap = native.FromNative();
    }

It seems as though the Andriod app may not be referencing the proper build of the Splat libraries. When I monitor paths containing %USERPROFILE%\.nuget\packages\splat in ProcMon I don't see any attempt by Visual Studio to open/read anything other than files in the .\netstandard2.0 directories during the build process.

When I open the netstandard2.0 libraries in DotPeek I can see that the class BitmapMixins is not included, but it is included in the monoandroid90 builds.

How do I get the reference to Splat in the Android project to pull in the proper build of Splat?

Example project can be found here: https://github.com/jctlp/SplatBitmap

h0meBrewer
  • 31
  • 5

1 Answers1

0

The error caused by that you did not have the extension methods to assist with dealing with Bitmaps of ToNative and FromNative.

Please do not add reference by installing the Splat from NuGet directly. Add reference to the whole project of Splat would be okay.

Download the whole Splat project from the link below. https://github.com/reactiveui/splat.git

I create a Xamarin.forms app named App1. And create a class Class2.cs in App1.Android. When I add reference to Splat from the project. It works well with ToNative and FromNative extension method.

Please note: Do not use the Bitmap, use Android.Graphics.Drawables.Drawable or var instead.

public void Bar(IBitmap source)
    {
        Android.Graphics.Drawables.Drawable native = source.ToNative();//var
        IBitmap bitmap = native.FromNative();
    }

enter image description here

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17