I'd like to announce the release of sysdrawing-coregraphics with support for Unified.
sysdrawing-coregraphics is an implementation of much of the System.Drawing API using CoreGraphics for the implementation. This means it has support for both Xamarin.Mac and Xamarin.iOS.
This project has been around for awhile with Classic support, but now has been updated to work with Unified Xamarin.Mac/Xamarin.iOS.
Download the build here: http://download.xamarin.com/system-drawing/sysdrawing-coregraphics-Cycle6.zip
View the project here: https://github.com/mono/sysdrawing-coregraphics
Samples are here: https://github.com/mono/sysdrawing-coregraphics/tree/master/Samples
Please note, this is a community project, and not an officially supported part of the Xamarin platform.
Posts
Thought I'd give this a spin as I'd ultimately like to migrate a classic app away from the old System.Drawing namespace to the new unified world. Only snag is I can't seem to get it to compile in a simple project. I created a default unified C# app targeting .NET 4.5, added a reference to the assembly above and tried to compile this code:
using( var image = new Bitmap( 600, 400 ) ) { }
However I get the following error:
Now System.Drawing.Size is defined in Xamarin.Mac which I'm referencing so I'm wondering if the Cycle6 assembly above is referencing a different version or something? I'm running Xamarin.Mac 2.4.1.6 (Indie). Any thoughts? Sample project attached.
Well sysdrawing-coregraphics does indeed depend on OpenTK but if I add a reference to the one included in the Xamarin.Mac framework folder it has System.Drawing.Color defined which is also defined in the sysdrawing-coregraphics version of System.Drawing.dll. This means anything referencing Color will not compile meaning I'm dead in the water currently unfortunately.
Hey John, apologies on the delay in response, I was out sick.
Did you accidentally add the mobile version of OpenTK or System.Drawing. You need:
/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/OpenTK.dll
and
mac/xm45/System.Drawing.dll (from the zip)
if you are targeting the XM 4.5 target framework.
If that does not help, please post the build log on a pastebin service (like gist) and post a link here for me to look at.
No worries! So /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/OpenTK.dll is actually an alias to /Library/Frameworks/Xamarin.Mac.framework/Versions/2.4.1.6/lib/reference/net_4_5/OpenTK.dll and that does contain a definition for some System.Drawing types (the other version in /.../Versions/2.4.1.6/lib/reference/net_4_5/full/ does not).
Likewise the System.Drawing.dll in sysdrawing-coregraphics-Cycle6/mac/xml45/System.Drawing.dll also contains System.Drawing.Color - screenshot below:
I've copied them multiple times to ensure I'm not bringing a mobile version over. The build log is here:
http://pastebin.com/Rxdng0rH
Hopefully you can see what rookie mistake I'm making!
Hmm. I have:
Xamarin.Mac
Version: 2.4.1.6 (Business Edition)
and I made a new XM Unified project, added SD and OpenTK and it built fine for me.
Could you clean, zip, and attach your test project somewhere for me to look at?
Attached below is a newly created and cleaned test app. It targets .NET 4.5. It would build fine so long as I didn't reference System.Drawing.Color which I'm doing here.
I can reproduce that. I'm not sure how that slipped by. Let me get back to you...
Phew, at least I wasn't making a rookie mistake!
Cool!
@JohnConners - Could you please try this version?
It turns out to be busted for both XM 4.5 and Mobile.
https://www.dropbox.com/s/2ejrtqcxy9vcz1r/sysdrawing-coregraphics-Cycle6-fixed.zip?dl=0
It has not gone through official QA, but it should have it fixed [1]. It works for me locally and my test case.
[1] - https://github.com/mono/sysdrawing-coregraphics/commit/fc3a0ac290ef42fd26b5fa4c0a0b98c8f24c4ef8
That's got me up and running - thanks!
If I find any bugs and what not is the GitHub page the best place to report them?
In this one specific case (this does not apply to anything else XM related for anyone else reading), Yes.
Since this is a community project (that I just happened to spend some time on, issues on the github page is preferred over bugzilla.
Chris, this is great. However, I'm getting compile errors on System.Drawing.Color references in my Xamarin.Mac application. I see that the color classes are only included in the IOS builds so are we supposed to be getting Color et al. from some other reference in XM?
Unfortunately, due to legacy reasons we can't change now, since it came first, System.Drawing.Color is provided by OpenTK:
/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/OpenTK.dll (Mobile)
/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/OpenTK.dll (XM 4.5)
Thanks, Chris. I got it working. BTW, I'm very grateful for this library.
Hi,
I'm trying to use sysdrawing-coregraphics (System.Drawing) in VisualStudio for Mac, but I encountered some errors.
Even after adding reference to OpenTK, I still get the error:
In fact, after opening the OpenTK in the VS Object Browser, I can't find Size in System.Drawing namespace.
Note that I tried both OpenTK available in VS and building it from sources (which indeed seems very different), but none worked.
@teejay87 You very likely have a mismatch between Xamarin.Mac, OpenTK, and System.Drawing assemblies.
Since you can't find System.Drawing, I assume you are using XM 4.5 Target Framework
Did you reference the correct OpenTK? (The one from mono/4.5 and not mono/Xamarin.Mac)?
If unclear, please post your csproj.
@ChrisHamons
I'm really new to Xamarin / VS Mac, so I could very likely have done some basic mistake.
The Xamarin.Mac assembly is the one VS Mac automatically adds when creating a new project:
/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/Xamarin.Mac.dll
The OpenTK assembly was the one that appears in the "Package" tab of the "Modify reference" dialog
/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/OpenTK.dll
Now I tried to reference the one in:
/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/OpenTK.dll
and it works...!
But... Am I missing something? Am I mixing non-mixable libraries?
Thanks for your time
Sorry for the delay in response, I was out on sick time yesterday.
So if you are using the "mobile" XM - mono/Xamarin.Mac/Xamarin.Mac.dll you should use the mobile OpenTK - mono/Xamarin.Mac/OpenTK.dll
The fact that it doesn't makes me think you are using the wrong System.Drawing one. Are you using the bin/mobile version?
Could you attach an example somewhere for me to look at if not?
Hi, I'm alittle bit beginner with compiling libraries, I'm using Xamarin on mac I tried to compile the library I got the following.
make: *** No rule to make target
../mono/mcs/class/System.Drawing/System.Drawing.Drawing2D/Blend.cs', needed by
bin/ios/System.Drawing.dll'. Stop.any ideas?
As the readme states:
It looks like you don't have mono next to the checkout.
git clone [email protected]:mono/mono.git
on the directory that contains your sysdrawing checkout (so the two folders are side by side) should set you up.
Thanks I built it, and I added it to the references,
Now I'm getting the following error.
(Path).../AvicennaPage.xaml.cs(4,4): Error CS7069: Reference to type
System.ICloneable' claims it is defined assembly
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', but it could not be found (CS7069) (Avicenna)I am getting this error while running sample xamarin.UITest application in visual studio 2015.But i have downloaded and installed the System.Drawing.dll.
What can i do next?
Anyone Knows please do help.Thanks in advance.
Severity Code Description Project File Line Suppression State
Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'System.Configuration.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) CreditCardValidator.Droid
The error roughly says "I can't find System.Configuration". The "Mono for Android" part makes me think you are using Android? sysdrawing-coregraphics uses CoreGraphics, which is only available for macOS and iOS.
In any case, please start a new topic in the right forum. This is unrelated enough.
I'm trying to convert my project from Xamarin.Mac mobile to Xamarin.Mac 4.5.
Now I get errors with drawing. When building it says that System.Drawing.Color is referenced multiple times and if I look at the System.Drawing and the OpenTK assemblies, they both contain a Color class. Did anyone else run into this?
I may be using the wrong System.Drawing assembly.
Minimal csproj: (from new test project)
csproj from my actual project (same error with multiple Color types):
As I mentioned before @FrederikTheisen, this is unrelated to the original thread.
Please create a new thread.
Also note you are mixing:
<HintPath>..\..\..\Downloads\sysdrawing-coregraphics-Cycle6-2\mac\xm45\System.Drawing.dll</HintPath>
with
<HintPath>..\..\..\..\..\Library\Frameworks\Xamarin.Mac.framework\Versions\3.0.0.398\lib\reference\net_4_5\OpenTK.dll</HintPath>
3.0 is Cycle 9.
I'm not completely shocked that isn't working out of the box. You'll likely need to build a sysdrawing-coregraphics against C9.
But in any case, another thread, so we can stop spamming people on this thread.
HI all,
I'm a newbie on Xamarin. :-)
So I downloaded the build .ZIP but.... where do I have to install those files ?
Thanks and congrats for your work !
Pierre
So you can either build the assemblies yourself (see directions on github) or download the ones I made against C9 here:
https://forums.xamarin.com/discussion/comment/263406/#Comment_263406
This isn't an SDK you install, just raw files you reference in your project. It is not uncommon to add a folder named external in your project, and check in copies into your project.
Chris, I downloaded your sysdrawing-coregraphics-Cycle6.zip, added a reference to System.Drawing.dll, and OpenTK.dll at /Library/Frameworks/Xamarin.Mac.framework/Versions/3.8.1.0/lib/reference/mobile/OpenTK.dll, but I am getting the following error:
The type 'Color' exists in both 'OpenTK, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' and 'System.Drawing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' (CS0433) (PDFTestOSX)
Also, I would prefer to build this System.Drawing from source, but I am unable.
Too much trouble?
I have opened an issue on GitHub.
@RamonMendes See https://forums.xamarin.com/discussion/comment/263406/#Comment_263406
Hi @ChrisHamons ,
I was able to build the sysdrawing-coregraphics from source and got some DLLs in bin folder. Then I created a simple Xamarin.iOS project and referenced the System.Drawing.dll in bin/iOS folder. During compilation I am getting:
MTOUCH: warning MT0136: Cannot find the assembly 'Xamarin.Mac, Version=0.0.0.0, ...'
MTOUCH: error MT2001: Could not link assemblies. Reason: Error while processing references of 'test-app...'
I don't understand why does it look for Xamarin.Mac when targeting Xamarin.iOS. I am not using the System.Drawing library directly but rather using 3rd party library which internally uses System.Drawing.
I would be glad if you could give me any directions how to solve my problem.
Hmm, it sounds like your 3rd party library is likely the culprit.
I would start by running
monop --refs -r:YOUR_LIB
on the libraries you are trying to link to see who is trying to pull in XM.Also, please start another thread. This is from 2017 and is notifying everyone on it.