Type with the Splat library and Xamarin.Mac

I have a Xamarin.iOS project that uses the splat https://github.com/paulcbetts/splat library to make System.Drawing types available in a portable class library. If the parent class uses (say) System.Drawing.RectangleF, then using Splat, it is great for subclassing this class in Xamarin.IOS code. However, the same does not apply to Xamarin.Mac, at least not in the way I do it. Different types conflict with themselves - at the minimum of Point and RectangleF.

I do not know if this is due to recent Xamarin updates (prior to Xamarin 6) or not.

The following is sample code, and I'm doing a complete project demonstrating the problem available on Github. https://github.com/verybadcat/splat - macbug branch.

It is similar to the problem [ Splat [0.3.4] on Xamarin.iOS described here : problems 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 fine:

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

Mac Project - Doesn't Create:

 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 create a Mac project?

+6
source share
1 answer

Ok, 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 really says: “Splat claimed that RectangleF was declared, but I can’t find it. Oh, and their thing and RectangleF do not match the one I can find.

What if you look at the source code, this is absolutely true. In a Splat-portable language, they declare their own RectangleF class, but the "bait-and-switch" of Splat-XamarinMac does not have any type or forwarder.

You can fix this by adding TypeForwardedSystemDrawing.cs to your Split-XamarinMac project by rebuilding (and commenting on or fixing a UIKit compilation error).

Feel free to open a problem with the Splat team to fix this at their end.

Note that if you try to port Splat to the target infrastructure of XM 4.5, you will need to open OpenTK, because for various reasons obsolete 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 
+3
source

All Articles