Skip to content

[IOS Xamarin] System.ExecutionEngineException: Attempting to JIT compile method 'void SixLabors.ImageSharp.Formats.Png.PngScanlineProcessor:ProcessRgbScanline<SixLabors.ImageSharp.PixelFormats.Rgba32> #1708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
MichielDG opened this issue Jul 19, 2021 · 11 comments
Labels
area:aot upstream-issue Issue depends on upstream dependency fix.

Comments

@MichielDG
Copy link

MichielDG commented Jul 19, 2021

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

In a xamarin forms for IOS project I'm using the method Image.Load to load a PNG image. I used it with imagedecoder and without but the same issue exists. The error I get is:

PngDecoderCore.ProcessDefilteredScanline[TPixel] (System.ReadOnlySpan`1[T] defilteredScanline, SixLabors.ImageSharp.ImageFrame`1[TPixel] pixels, SixLabors.ImageSharp.Formats.Png.PngMetadata pngMetadata)
System.ExecutionEngineException: Attempting to JIT compile method 'void SixLabors.ImageSharp.Formats.Png.PngScanlineProcessor:ProcessRgbScanline<SixLabors.ImageSharp.PixelFormats.Rgba32> (SixLabors.ImageSharp.Configuration,SixLabors.ImageSharp.Formats.Png.PngHeader&,System.ReadOnlySpan`1<byte>,System.Span`1<SixLabors.ImageSharp.PixelFormats.Rgba32>,int,int,bool,SixLabors.ImageSharp.PixelFormats.Rgb48,SixLabors.ImageSharp.PixelFormats.Rgb24)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

Stack traces
SixLabors.ImageSharp.Formats.Png
PngDecoderCore.ProcessDefilteredScanline[TPixel] (System.ReadOnlySpan`1[T] defilteredScanline, SixLabors.ImageSharp.ImageFrame`1[TPixel] pixels, SixLabors.ImageSharp.Formats.Png.PngMetadata pngMetadata)
SixLabors.ImageSharp.Formats.Png
PngDecoderCore.DecodePixelData[TPixel] (System.IO.Compression.DeflateStream compressedStream, SixLabors.ImageSharp.ImageFrame`1[TPixel] image, SixLabors.ImageSharp.Formats.Png.PngMetadata pngMetadata)
SixLabors.ImageSharp.Formats.Png
PngDecoderCore.ReadScanlines[TPixel] (SixLabors.ImageSharp.Formats.Png.PngChunk chunk, SixLabors.ImageSharp.ImageFrame`1[TPixel] image, SixLabors.ImageSharp.Formats.Png.PngMetadata pngMetadata)
SixLabors.ImageSharp.Formats.Png
PngDecoderCore.Decode[TPixel] (SixLabors.ImageSharp.IO.BufferedReadStream stream, System.Threading.CancellationToken cancellationToken)
SixLabors.ImageSharp.Formats
ImageDecoderUtilities.Decode[TPixel] (SixLabors.ImageSharp.Formats.IImageDecoderInternals decoder, SixLabors.ImageSharp.Configuration configuration, System.IO.Stream stream, System.Func`3[T1,T2,TResult] largeImageExceptionFactory)
SixLabors.ImageSharp.Formats
ImageDecoderUtilities.Decode[TPixel] (SixLabors.ImageSharp.Formats.IImageDecoderInternals decoder, SixLabors.ImageSharp.Configuration configuration, System.IO.Stream stream)
SixLabors.ImageSharp.Formats.Png
PngDecoder.Decode[TPixel] (SixLabors.ImageSharp.Configuration configuration, System.IO.Stream stream)
SixLabors.ImageSharp.Formats.Png
PngDecoder.Decode (SixLabors.ImageSharp.Configuration configuration, System.IO.Stream stream)
SixLabors.ImageSharp
Image.Decode (System.IO.Stream stream, SixLabors.ImageSharp.Configuration config)
SixLabors.ImageSharp
Image+<>c__DisplayClass137_0.<Load>b__0 (System.IO.Stream s)
SixLabors.ImageSharp
Image.WithSeekableStream[T] (SixLabors.ImageSharp.Configuration configuration, System.IO.Stream stream, System.Func`2[T,TResult] action)
SixLabors.ImageSharp
Image.Load (SixLabors.ImageSharp.Configuration configuration, System.IO.Stream stream, SixLabors.ImageSharp.Formats.IImageFormat& format)
SixLabors.ImageSharp
Image.Load (SixLabors.ImageSharp.Configuration configuration, System.Byte[] data, SixLabors.ImageSharp.Formats.IImageFormat& format)
SixLabors.ImageSharp
Image.Load (System.Byte[] data, SixLabors.ImageSharp.Formats.IImageFormat& format)

Steps to Reproduce

Use an IOS Xamarin project and execute the following code:

byte[] imageData; // fill this with a png
var imageDecoder = new SixLabors.ImageSharp.Formats.Png.PngDecoder();
var image = Image.Load(imageData, imageDecoder);
  • ImageSharp version: 1.0.3
  • Environment (Operating system, version and so on): IOS 14.5
  • .NET Standard: 2.0
@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Jul 19, 2021

You've chopped off the first line of the exception message that tells us the exception thrown can you please supply it?

Can you also update the target framework. It can't be .NET Standard 2.0 unless it is a class library.

We'll also need the image.

Edit.

Just realized you put the exception in the title. You'll need to raise this upstream. It's an issue with the Xamarin AOT compiler not with ImageSharp. See this note as to why. #1703 (comment)

We have tried to patch our way around issues so I would suggest trying one of our nightly builds to see if we've managed to avoid this particular issue.

@JimBobSquarePants JimBobSquarePants added area:aot upstream-issue Issue depends on upstream dependency fix. labels Jul 19, 2021
@MichielDG
Copy link
Author

You've chopped off the first line of the exception message that tells us the exception thrown can you please supply it?

Can you also update the target framework. It can't be .NET Standard 2.0 unless it is a class library.

We'll also need the image.

Edit.

Just realized you put the exception in the title. You'll need to raise this upstream. It's an issue with the Xamarin AOT compiler not with ImageSharp. See this note as to why. #1703 (comment)

We have tried to patch our way around issues so I would suggest trying one of our nightly builds to see if we've managed to avoid this particular issue.

It is implemented in a class library. That class library is used inside an Xamarin Forms IOS project (Xamarin Forms version 5.0.0.2012).
I just tried SixLabors.ImageSharp version 1.0.4-alpha.0.49. I have the same issue with this version.
I have the problem with every picture that is taken with the Xamarin.Essentials.MediaPicker in IOS.

@JimBobSquarePants
Copy link
Member

Yeah it’s not the image (hence the reason I struck out the comment) it’s Xamarins AOT compiler. You should raise the issue upstream with them.

@softlion
Copy link

Same issue.

It's because the template class is too complicated.

Error: Failed to save measurement (exception) | ExecutionEngineException: Attempting to JIT compile method 'void SixLabors.ImageSharp.Formats.Png.PngScanlineProcessor:ProcessRgbaScanline<SixLabors.ImageSharp.PixelFormats.Rgba32> (SixLabors.ImageSharp.Configuration,SixLabors.ImageSharp.Formats.Png.PngHeader&,System.ReadOnlySpan`1<byte>,System.Span`1<SixLabors.ImageSharp.PixelFormats.Rgba32>,int,int)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

@JimBobSquarePants
Copy link
Member

It's because the template class is too complicated.

I don’t understand what you mean by this

@JimBobSquarePants
Copy link
Member

Has anyone raised the the issue with Xamarin? As I said before. The issue is with their compiler

@softlion
Copy link

They won't do anything. They are full on MAUI with a new AOT "compiler" (which may have the same limitations).

AOT can't, sometime, find out all the template classes that are used in a library. As live code generation is refused by apple devices.

@JimBobSquarePants
Copy link
Member

We don’t do any live code generation. No emit, nothing dynamic. Raise the issue with them.

@softlion
Copy link

It's not dynamic code. It's templated classes.

@softlion
Copy link

https://docs.microsoft.com/en-us/xamarin/ios/internals/limitations

see "Limited Generics Support"

@JimBobSquarePants
Copy link
Member

I’m closing this. The conversation has ceased to be constructive. There are no issues with the ImageSharp codebase

@SixLabors SixLabors locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:aot upstream-issue Issue depends on upstream dependency fix.
Projects
None yet
Development

No branches or pull requests

3 participants