6

I have an Xamarin.iOS project that uses the splat library https://github.com/paulcbetts/splat to make System.Drawing types available in portable class library. If a parent class uses (say) System.Drawing.RectangleF, then by using Splat, it works just fine to subclass this class in Xamarin.IOS code. However, the same is not true of Xamarin.Mac, at least not the way I am doing it. Various types conflict with themselves -- at a minimum Point and RectangleF.

I don't know if this is related to Xamarin's recent updates (to Xamarin 6) or not.

Some sample code is below, and I'm making a full project demonstrating the problem available on Github. https://github.com/verybadcat/splat -- macbug branch.

It looks similar to the problem described here [Splat [0.3.4] on Xamarin.iOS: issues with RectangleF and PointF.

Portable Class Library project:

using System.Drawing;
namespace PCL
{
  public class RectOwner
  {
    public RectangleF Rect { get; set;}
  }
}

IOS project -- this works just fine:

using PCL;

namespace IOSApp
{
  public class RectOwnerIOS: RectOwner
  {
    public RectOwnerIOS ()
    {
      this.Rect = new System.Drawing.RectangleF (10, 20, 30, 40);
    }
  }
}

Mac project -- does not build:

using PCL;


namespace MacApp
{
  public class RectOwnerSubclass: RectOwner
  {
    public RectOwnerSubclass ()
    {
      this.Rect = new System.Drawing.RectangleF (5, 6, 7, 8); // errors here:
      // /Users/william/Documents/splat/MacApp/RectOwnerMac.cs(16,16): Error CS7069: Reference to type `System.Drawing.RectangleF' claims it is defined assembly `Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null', but it could not be found (CS7069) (MacApp)
     // /Users/william/Documents/splat/MacApp/RectOwnerMac.cs(23,23): Error CS0029: Cannot implicitly convert type `System.Drawing.RectangleF [Xamarin.Mac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]' to `System.Drawing.RectangleF [Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null]' (CS0029) (MacApp)
    }
  }
}

How can I get the Mac project to build?

Community
  • 1
  • 1
William Jockusch
  • 26,513
  • 49
  • 182
  • 323

1 Answers1

3

Alright, so the error in question is:

RectOwnerMac.cs(11,12): error CS7069: Reference to type `System.Drawing.RectangleF' claims it is defined assembly `Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null', but it could not be found
RectOwnerMac.cs(11,19): error CS0029: Cannot implicitly convert type `System.Drawing.RectangleF [Xamarin.Mac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]' to `System.Drawing.RectangleF [Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null]'

Which is really saying "Splat claimed to have a RectangleF declared, but I can't find it. Oh, and their thing and the RectangleF doesn't match the one I can find.

Which if you look at the source code, is completely true. In Splat-portable they declare their own RectangleF class, but the "bait-and-switch" Splat-XamarinMac does not have one, nor a type forwarder.

You can fix this by adding TypeForwardedSystemDrawing.cs to the Split-XamarinMac project, rebuilding (and commenting out or fixing the UIKit compile error).

Feel free to open an issue with the Splat team to fix this on their end.

Do note, if you try to port Splat to the XM 4.5 target framework, you'll need to pull in OpenTK, because for various legacy reasons the SD types are defined there:

$ monop -r:/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/Xamarin.Mac.dll | grep Drawing.Rectangle
$ monop -r:/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/OpenTK.dll | grep Drawing.Rectangle
System.Drawing.Rectangle
System.Drawing.RectangleF
Chris Hamons
  • 1,510
  • 11
  • 22