sysdrawing-coregraphics with XM 4.5

@FrederikTheisen said:
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)

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProjectGuid>{365A0970-BA60-446D-8C7E-D618EE51D3EB}</ProjectGuid>
    <ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <OutputType>Exe</OutputType>
    <RootNamespace>DrawingTestApp3</RootNamespace>
    <AssemblyName>DrawingTestApp3</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
    <UseXamMacFullFramework>true</UseXamMacFullFramework>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <EnableCodeSigning>false</EnableCodeSigning>
    <CodeSigningKey>Mac Developer</CodeSigningKey>
    <CreatePackage>false</CreatePackage>
    <EnablePackageSigning>false</EnablePackageSigning>
    <IncludeMonoRuntime>false</IncludeMonoRuntime>
    <UseSGen>true</UseSGen>
    <UseRefCounting>true</UseRefCounting>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <EnableCodeSigning>false</EnableCodeSigning>
    <CreatePackage>true</CreatePackage>
    <EnablePackageSigning>false</EnablePackageSigning>
    <IncludeMonoRuntime>true</IncludeMonoRuntime>
    <UseSGen>true</UseSGen>
    <UseRefCounting>true</UseRefCounting>
    <LinkMode>None</LinkMode>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="Xamarin.Mac" />
    <Reference Include="OpenTK">
      <HintPath>..\..\..\..\..\Library\Frameworks\Xamarin.Mac.framework\Versions\3.0.0.398\lib\reference\net_4_5\OpenTK.dll</HintPath>
    </Reference>
    <Reference Include="System.Drawing">
      <HintPath>..\..\..\Downloads\sysdrawing-coregraphics-Cycle6-2\mac\xm45\System.Drawing.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-128.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-128%402x.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-16.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-16%402x.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-256.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-256%402x.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-32.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-32%402x.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-512.png" />
    <ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-512%402x.png" />
    <ImageAsset Include="Assets.xcassets\Contents.json" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Resources\" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Info.plist" />
    <None Include="Entitlements.plist" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Main.cs" />
    <Compile Include="AppDelegate.cs" />
    <Compile Include="ViewController.cs" />
    <Compile Include="ViewController.designer.cs">
      <DependentUpon>ViewController.cs</DependentUpon>
    </Compile>
    <Compile Include="DrawingView.cs" />
    <Compile Include="DrawingView.designer.cs">
      <DependentUpon>DrawingView.cs</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <InterfaceDefinition Include="Main.storyboard" />
    <InterfaceDefinition Include="DrawingView.xib" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
</Project>

csproj from my actual project (same error with multiple Color types):

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProjectGuid>{DE253DD2-CB6A-4C18-A905-CE9B607F969A}</ProjectGuid>
    <ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <OutputType>Exe</OutputType>
    <RootNamespace>GeneViewerMac</RootNamespace>
    <AssemblyName>GeneViewer</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
    <UseXamMacFullFramework>true</UseXamMacFullFramework>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <EnableCodeSigning>false</EnableCodeSigning>
    <CodeSigningKey>Mac Developer</CodeSigningKey>
    <CreatePackage>false</CreatePackage>
    <EnablePackageSigning>false</EnablePackageSigning>
    <IncludeMonoRuntime>false</IncludeMonoRuntime>
    <UseSGen>true</UseSGen>
    <UseRefCounting>true</UseRefCounting>
    <Profiling>true</Profiling>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <EnableCodeSigning>false</EnableCodeSigning>
    <CreatePackage>true</CreatePackage>
    <EnablePackageSigning>false</EnablePackageSigning>
    <IncludeMonoRuntime>true</IncludeMonoRuntime>
    <UseSGen>true</UseSGen>
    <UseRefCounting>true</UseRefCounting>
    <LinkMode>None</LinkMode>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Net" />
    <Reference Include="System.Json" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Xml.Serialization" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Windows" />
    <Reference Include="System.Web.Services" />
    <Reference Include="System.IO.Compression.FileSystem" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.IO.Compression" />
    <Reference Include="System.ServiceModel.Web" />
    <Reference Include="System.Net.Http.WinHttpHandler" />
    <Reference Include="System.Data.Services.Client" />
    <Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
    <Reference Include="System.Security" />
    <Reference Include="Mono.Security" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="Xamarin.Mac" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="Mono.CSharp" />
    <Reference Include="Newtonsoft.Json">
      <HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\netstandard1.3\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System.Drawing">
      <HintPath>..\..\..\Downloads\sysdrawing-coregraphics-Cycle6-2\mac\xm45\System.Drawing.dll</HintPath>
    </Reference>
    <Reference Include="OpenTK">
      <HintPath>..\..\..\..\..\Library\Frameworks\Xamarin.Mac.framework\Versions\3.0.0.398\lib\reference\net_4_5\OpenTK.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Contents.json" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_128x128.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_128x128%402x.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_16x16.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_16x16%402x.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_256x256.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_256x256%402x.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_32x32.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_32x32%402x.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_512x512.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\Icon.iconset\icon_512x512%402x.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\Contents.json" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\16.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\32.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\64.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\128.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\256.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\512.png" />
    <ImageAsset Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\1024.png" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Resources\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\AppIcon3.appiconset\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\AppIcon2.appiconset\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\AppIcon1.appiconset\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\Image01.imageset\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\AppIcon4.appiconset\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\AppIcon5.appiconset\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\AppIcon6.appiconset\" />
    <Folder Include="Resources\GeneViewerMac\Images.xcassets\AppIcon7.appiconset\" />
    <Folder Include="CrossPlatformFiles\" />
    <Folder Include="Data\" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Info.plist" />
    <None Include="Entitlements.plist" />
    <None Include="packages.config" />
    <None Include="CrossPlatformFiles\App_localservice.cs" />
    <None Include="CrossPlatformFiles\App_webservice.cs" />
    <None Include="OpenTK.dll.config" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Main.cs" />
    <Compile Include="App.cs" />
    <Compile Include="MainViewController.cs" />
    <Compile Include="MainViewController.designer.cs">
      <DependentUpon>MainViewController.cs</DependentUpon>
    </Compile>
    <Compile Include="NewDNAViewController.cs" />
    <Compile Include="NewDNAViewController.designer.cs">
      <DependentUpon>NewDNAViewController.cs</DependentUpon>
    </Compile>
    <Compile Include="CrossPlatformFiles\GeneViewerClasses.cs" />
    <Compile Include="MainWindowController.designer.cs">
      <DependentUpon>MainWindowController.cs</DependentUpon>
    </Compile>
    <Compile Include="MainSplitViewController.cs" />
    <Compile Include="MainSplitViewController.designer.cs">
      <DependentUpon>MainSplitViewController.cs</DependentUpon>
    </Compile>
    <Compile Include="ControlAssets\NSTextViewAsset.cs" />
    <Compile Include="ControlAssets\NSTextViewAsset.designer.cs">
      <DependentUpon>NSTextViewAsset.cs</DependentUpon>
    </Compile>
    <Compile Include="App.designer.cs">
      <DependentUpon>App.cs</DependentUpon>
    </Compile>
    <Compile Include="ControlAssets\MainWindowBrowser.cs" />
    <Compile Include="ControlAssets\MainWindowBrowser.designer.cs">
      <DependentUpon>MainWindowBrowser.cs</DependentUpon>
    </Compile>
    <Compile Include="NewDNAWindowController.designer.cs">
      <DependentUpon>NewDNAWindowController.cs</DependentUpon>
    </Compile>
    <Compile Include="NewDNAWindowController.cs" />
    <Compile Include="AnalyzerSettingsViewController.designer.cs">
      <DependentUpon>AnalyzerSettingsViewController.cs</DependentUpon>
    </Compile>
    <Compile Include="AnalyzerSettingsViewController.cs" />
    <Compile Include="AnalyzerSettingsWindowController.cs" />
    <Compile Include="AnalyzerSettingsWindowController.designer.cs">
      <DependentUpon>AnalyzerSettingsWindowController.cs</DependentUpon>
    </Compile>
    <Compile Include="AnalyzerViewController.cs" />
    <Compile Include="AnalyzerViewController.designer.cs">
      <DependentUpon>AnalyzerViewController.cs</DependentUpon>
    </Compile>
    <Compile Include="MainWindowController.cs" />
    <Compile Include="CrossPlatformFiles\dna_analyzerclass.cs" />
    <Compile Include="Resources\GeneViewerMac\DrawingView.cs" />
    <Compile Include="Resources\GeneViewerMac\DrawingView.designer.cs">
      <DependentUpon>DrawingView.cs</DependentUpon>
    </Compile>
    <Compile Include="PlasmidMapCircular.cs" />
    <Compile Include="PlasmidMapCircular.designer.cs">
      <DependentUpon>PlasmidMapCircular.cs</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <InterfaceDefinition Include="Main.storyboard" />
  </ItemGroup>
  <ItemGroup>
    <BundleResource Include="Data\data_ntDict.txt" />
    <BundleResource Include="Data\data_RestrictionSites.xml" />
    <BundleResource Include="Data\data_ntCompDict.txt" />
    <BundleResource Include="Data\data_DNAFeatures.xml" />
    <BundleResource Include="Data\data_colorDict.txt" />
    <BundleResource Include="Data\data_codonDict.txt" />
    <BundleResource Include="Data\data_aminoAcidPropertiesXML.txt" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
</Project>

So I'm mixing two assemblies that are not compatible.

So I need to 'build' a new System.Drawing.dll for Xamarin cycle 9?

Is this System.Drawing approach even a reasonable choice for drawing simple 2D thing on screen?
This is what I'm using it for:

Best Answers

Answers

  • FrederikTheisenFrederikTheisen DKMember ✭✭

    Bump, I'm pretty much stuck in limbo between Mobile and XM4.5 target framework and I can't continue working on my app before I know which way to go.

  • FrederikTheisenFrederikTheisen DKMember ✭✭

    Tbh, if I have any option to use System.Drawing I would like to try that since I already have a thousand lines or so of code made for a very similar API (and about 1 third of that working on Xamarin.Mac Mobile).
    But I don't think it's possible with XM4.5.

  • FrederikTheisenFrederikTheisen DKMember ✭✭

    Thanks a bunch.

    I got your sample working and have also implemented it in my own app.
    Though I had a problem when referencing WindowsAzure.Mobile it started saying that multiple Rectangles (+F, Point + F, Size + F,) existed. Referencing the WindowsAzure.Mobile did the same.

    I have written my own 'Rectangle' ect. classes and made some methods within the DrawingView which take care of the drawing, so no problems so far, just though I'd mention it. The Azure assembly comes from some net45 folder and I can't find any Rectangle classes within it.

    Hopefully I'll finally be able to connect to my server.

  • zintjrzintjr Member ✭✭
    edited August 28

    @ChrisHamons

    Hey Chris, trying to use System.Drawing and running into all kinds of issues. I've tried the following packages with no luck:

    --runtime.osx.10.10-x64.CoreCompat.System.Drawing
    --CoreCompat.System.Drawing.v2

    However neither of those will resolve the error - "Reference to type 'Image' claims it is defined in System.Drawing but it could not be found."

    So after following thru this thread I landed on the sysdrawing-coregraphics github page which seems like it might work but I'm really lost on how to build the solution. Specifically the directions that state the following:

    -You will need a checkout of Mono as a peer module to this module.
    -The solution references code from mono and corefx, and expects Mono with submodules to be checked out as a peer directory to this directory.

    When it says "peer module" is that equivalent to a normal directory? Is it saying that the Mono directory should reside in the same folder as the sysdrawing-coregraphics folder?

    And in the second statement it says "expects Mono with submodules to be checked out as a peer directory". Is this just stating the same thing as the first statement in a different way?

    Sorry if the answer is obvious and I'm just missing it but rather new to git and could really use some hand holding here to figure out how to get this to build. If there is an equivalent nuget package that would be great, thanks for your help!

    Also is there a preferred Target Framework to use to get this to work. Right now my project is set to use "Xamarin.Mac Modern" and I tried changing the TargetFrameworkVersion element to 4.6.1 as suggested elsewhere in combination with the Full option but the project would not even load. Should I stick with modern or is Full the way to go? Thanks again!

  • zintjrzintjr Member ✭✭

    UPDATE: Got it to finally build with no errors by adding CoreCompat.System.Drawing.v2 and NetStandard.Library

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Interesting, I have never heard of that nuget before.

    Sorry the documentation wasn't clear. In multiple xamarin/mono projects we sometimes reach into other projects by checked them out side by side:

    mono/
    sysdrawing-coregraphics/

    in the same parent folder, and using relative paths to "get files". This makes it easier to grab new versions without doing submodule bump dancing.

    On the target framework question, I'd start with the documentation here

    https://docs.microsoft.com/en-us/xamarin/mac/platform/target-framework

    but the 10 second tl;dr is:

    • If you can use Modern, do so. It's smaller, leaner, and linking can really reduce package size.
    • If you need Full, go with it. It'll have a larger footprint but will be fine.
    • Just stay away from System unless you have no choice. Dragons live here unless you know what you're doing.
Sign In or Register to comment.