SolvedImageSharp Maintain Xamarin iOS support by keeping the library "AOT-proof"


Xamarin iOS users need to be able to "seed" open-generic library API-s with the help of AotCompilerTools, otherwise it will lead to runtime exceptions on that platform.

Related: #767, #785, #776, #800


Currently we are struggling to maintain this feature because of the following reasons:

  • There is no one in the core team having experience with Xamarin iOS or any other AOT platform.
  • We don't have any regression tests for this, we never know when a change breaks the "AOT-proofness" of an existing API
  • We have introduced a massive change with #904, which will most likely break AOT & Xamarin iOS for many existing API-s in RC1. I have defined a point in epic #907 to investigate this, however in practice it turned out that I hardly have the resources to do so during this summer. (Neither I think @JimBobSquarePants can make it.) Therefore it will most likely not happen for RC1.


With our current prioritites and resources, the only way to maintain this feature is community support. If you can provide any help (add missing AOT seeds, or fix regressions), feel free to open a Pull Request!

Long term solution

If someone could define a mono AOT test configuration for appveyor, that would be ace.

/CC @vicfergar @davilovick @gameleon-dev @Lapinou42 @dmanning23 @swoolcock

PS: Could someone do a favor and chack the latest MyGet dev builds from on Xamarin iOS? (JPEG, PNG, Resize, Quantization etc.)

40 Answers

✔️Accepted Answer

Ok wrote a quick&dirty iOS app that loads all the images in the test suite, and didn't run into any AoT/JIT errors. Whatever error it was hitting must have been fixed in #949

@gameleon-dev If you want to send me the specific .png I can double check that it will work going forward.

Here is the sample app with output:

Other Answers:

You should be good to go, I was able to load the attached image:

2019-08-07 17:24:44.794 ImageSharpTest.iOS[2745:131288] Testing Content/62653769-9175ed80-b95e-11e9-9a8d-348b071cb714.png
2019-08-07 17:24:45.439 ImageSharpTest.iOS[2745:131288]    ... SUCCESS!

I had a similar problem with Unity Android IL2CPP, but I found a solution.
Xamarin iOS and Unity Android IL2CPP both work with Mono, so I think you can solve it the same way.

According to the Unity manual, you need to write a specific code to make a particular generic method work.

This should probably cache all interface methods that have generic methods.
For example, this part.

I wanted to shrink a large PNG image, so I created the following code.

/// <summary>
/// Because it calls an internal class, it needs to be placed inside the ImageSharp project.
/// </summary>
static class UnityAoT<TPixel> where TPixel : unmanaged, IPixel<TPixel>
    /// <summary>
    /// call from <see cref="SixLabors.ImageSharp.Advanced.AotCompilerTools.Seed{TPixel}"/>
    /// </summary>
    internal static void UnitySeed()
    private static void AotCompileEncoder()
        default(PngEncoderCore).Encode<TPixel>(default, default, default);
    private static void AotCompileImageProcessor()
    private static void AotCompilerPixelSpecifics<TProc>()
        where TProc : class, ICloningImageProcessor
        default(TProc).CreatePixelSpecificCloningProcessor<TPixel>(default, default, default);
        default(TProc).CreatePixelSpecificProcessor<TPixel>(default, default, default);
    private static void AotCompileResampler()
    private static void AotCompileResamplers<TResampler>()
        where TResampler : struct, IResampler
        // TODO : Methodize it.

This is working fine, but doesn't allow me to do anything other than shrink.
I think we need to cache more methods to do all the processing.

Related Issues:

ImageSharp WebP Support
I am working on support for webp So far decoding of lossless images is almost done I will continue w...
ImageSharp Maintain Xamarin iOS support by keeping the library "AOT-proof"
Ok wrote a quick&dirty iOS app that loads all the images in the test suite and didn't run into any A...
efcore No executable found matching command "dotnet-ef" even after adding CLI
I has this issue and like to share I want to Migrate my Database with Models I am using EF Core 2.0 ...
efcore UseSqlServer() method is missing from Microsoft.EntityFrameworkCore.SqlServer 1.1.1
Hm - try manually adding the using statement using Microsoft.EntityFrameworkCore; and building again...
omnisharp vscode v1.23.1 fails to load Unity project, worked with v1.23.0
The problem is that the new .NET Core 3.1 SDK isn't supported by any current Mono release ...
omnisharp vscode [fail]: OmniSharp.MSBuild.ProjectManager: Attemped to update project that is not loaded.
Thanks a bunch! This solved the issue for me Steps taken Download version 1.15.2 (see link above ...
xunit .NET Core tests produce no output
After some exploration I figured out an easy solution: dotnet test --logger:console;verbosity=detail...
efcore How to write DbFunction's translation?
@Kation You actually does not need so much of code to use JSON_VALUE function Based on documentation...
efcore Inheritance problem with DbContext subclasses requiring constructor to supply DbContextOptions<DerivedContext>
I was able to resolve this without a hack by providing a protected constructor that uses DbContextOp...
omnisharp vscode Debug Console window cannot accept Console.ReadLine() input during debugging
From @kieferrm on December 17 2016 14:50 The debug console is output only From @LiangZugeng on Decem...
efcore MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferences
@AmSmart just to clarify in the documentation that @ajcvickers mentioned it gives updated code for t...
efcore error NU1202: Package dotnet-ef 3.0.1 is not compatible with netcoreapp3.0
@bricelam Presumably the workaround for anyone hitting this is to install the 3.0.0 version explicit...
efcore Could not load System.Diagnostics.DiagnosticSource
Looks like this only occurs on Class Library projects targeting netcoreapp1.1 Could not load file or...
efcore EF7 (RC1) - Cannot Skip() and Take() in SQL Server 2008
@tobbylee1 This API now uses a nested closure pattern: I am aware that SQL Server 2012 and above has...
efcore Problem with dotnet cli ef tools after upgrading to vs 2017 15.4.4 and november .net core rollup
I have the same predicament Error is occurring when running: dotnet ef migrations remove I was able ...
omnisharp vscode 'System' not found after update to dotnet core 3.0
I was able to resolve this issue by uninstalling mono via brew and letting omnisharp use the MSBuild...
omnisharp vscode Omnisharp can't find .NET SDK when open any C sharp project
Sometimes the Visual Studio warning will still persist even after installing the .NET SDK ...
efcore The instance of entity type cannot be tracked because another instance with the same key value for {'Id'} is already being tracked
Numerous issues I've been running into have one nasty root In a nutshell: I've learned the hard way ...
omnisharp vscode Debug multiple ASP.NET Core projects in Visual Studio Code
Try this also Moved from microsoft/vscode#25628 From @mdmoura VSCode Version: 1.11.2 OS Version: Win...
omnisharp vscode The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Solved this problem by adding omnisharp.json with Was asked to create new issue on #2876 Environment...
efcore Cannot be tracked because another instance of this type with the same key is already being tracked
@rickco75 I had same issue and get rid of it by below: In your case it will be: var record2 = _conte...
omnisharp vscode Format code returns: Sorry, but there is no formatter for 'csharp'-files installed.
Ah got it there was line csharp.format.enable: false in my user config after cleared that it started...
omnisharp vscode Issues when upgrading to 1.23.3 - Unity assembly definitions not found correctly
A temporary work-around to anyone who finds this for now: Right-click the C# extention from within V...
language ext FP design with language-ext
@andyigreg I have talked about this before with Free Monads and you can see the working in the Accou...
omnisharp vscode Always show "Downloading package 'OmniSharp (.NET 4.6 / x64)' (12310 KB) ."
Sorry for the delay I needed to get 1.6 out the door before taking some time to write up the steps b...
efcore Could not load file or assembly System.ComponentModel.Annotations, Version=
In some form this problem is already there for more then two years Hi the past few days I tried to g...
efcore Significant Query Slowdown When Using Multiple Joins Due To Changes In 3.0
I would like to chime in and say that we are also having this issue and is very problematic for us ...
omnisharp vscode The SDK 'Microsoft.NET.Sdk.Web' specified could not be found
Latest OmniSharp beta as of now is 3.5.0-beta.2204 which seem to work with the latest .NET Core SDK ...
efcore pluggable schemes for mapping c# names
update for efcore3 the Relational() methods have been removed in 469177a I am using EF Core with Pos...
efcore Distinguish cancellation from failure to allow different logging strategies
I think this should have a label urgent-fix not consider-for-next-release What problem are you tryin...
Newtonsoft.Json Serialization of decimals does not respect precision
I agree that this is unexpected behaviour at the very least and imho it is also a bug For 15 the pre...
Entitas CSharp Roslyn based code generator
Wooooot! Just generated the very first time! The current code generator relies on reflection which m...
GitVersion GitVersion on VSTS fails with hosted macOS and Linux agents
Under macOS (10.14) Since version 4.0.0 of GitVersion it seems to be supported to use the GitVersion...
language ext How do I use Try<T> with an existing method?
Anyone able to help me out here? Sorry if this is a dumb question but as I said I'm fairly new to FP...
efcore Mechanism/API to specify a default conversion for any property of a given type in the model
For EF Core 6.0.0-preview6: Value conversions were introduced by #242 Currently conversions are only...
efcore SQL Server Migrations: Idempotent scripts fails with 'invalid column name' (needs EXEC)
Hi Another workaround is to globally wrap SQL scripts with EXECUTE() statement I have encountered a ...
efcore Discussion for announcement: EF Core 2.0: design-time DbContext discovery changes
@markrendle After discussing with Hosting it sounds like Startup.Configure() should only be used to ...
choco PHP Package won't upgrade or uninstall - Path Bind Error
@jansohn only workaround that I know of currently is: Uninstall the package without running the unin...
MaterialDesignInXamlToolkit Could not load file or assembly 'MaterialDesignColors, Culture=neutral' or one of its dependencies
For folks still encountering this issue: this post by Carlos Anderson explains what's going on: Ther...
omnisharp vscode remove unused usings
Bump!.. This reasonably basic capability is a big miss on Visual Studio Code Environment data dotnet...
efcore No database provider has been configured
seems to me that the constructor is required when using services.AddDbContext<Db>(options => options...
azure sdk for net ClientServerCredential equivalent for simple apiKey authentication?
Here is my version of the ServiceClientCredentials for apiKey Is there support for swagger's concept...
VisualStudio Can't login to GitHub
@HisRoyalRedness is this still happening to you? If it is - the credentials are stored in the Window...
omnisharp vscode Problem after update to .NET SDK 2.2.202-1
For anyone trying to fix this quickly: which is followed by the list of versions $ sudo apt install ...
omnisharp vscode Omnisharp.msbuild.projectmanager - failed to load project file - no IntelliSense
I'm stuck on this issue with Ubuntu 19.04 I tried setting omnisharp.useGlobalMono: never (for those ...
omnisharp vscode C# Extension fails only for netcoreapp3.0 GA
Guys I've got the solution (for those who don't want to install VS2019) Go to Microsoft VS downloads...
StackExchange.Redis Could not load file or assembly System.Runtime.CompilerServices.Unsafe, Version=
For anyone else hitting this these issues prompted me to write up a more complete story on why this ...
choco Reboot - Pending File Rename Operations check returns true, even after reboot
I've seen the same behavior On running choco upgrade all -y (as Administrator) ...