Skip to content
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

Attempting to JIT compile method "(wrapper native-to-managed) int Emgu.CV.CvInvoke:CvErrorHandler (int,intptr,intptr,intptr,int,intptr)" while running in aot-only mode. #926

Open
hirendh opened this issue Apr 12, 2024 · 2 comments
Assignees

Comments

@hirendh
Copy link

hirendh commented Apr 12, 2024

We have created cross platform application in .Net MAUI with .Net 8 Latest Version. In app we have used Emgu.CV.runtime.maui.macos.4.8.1.5350.nupkg nuget package. when we use any operation related CvInvoke it's throw exception. Following is code in i got this exception.

Convert SKbitmap to Mat :

Mat source = new Mat();
 byte[] bytes;
 using (SKImage img = SKImage.FromBitmap(skBitmap))
 using (SKData data = img.Encode())
 {
             bytes = data.ToArray();
 }
 CvInvoke.Imdecode(bytes, ImreadModes.Unchanged, source);
  int channels = skBitmap.BytesPerPixel;
 source = new Mat(new System.Drawing.Size(skBitmap.Width, skBitmap.Height), DepthType.Cv8U, channels, 
skBitmap.GetPixels(), skBitmap.RowBytes);

throw Exception:

System.TypeInitializationException: TypeInitialization_Type, Emgu.CV.MatInvoke
 ---> System.TypeInitializationException: TypeInitialization_Type, Emgu.CV.CvInvoke
 ---> System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) int Emgu.CV.CvInvoke:CvErrorHandler (int,intptr,intptr,intptr,int,intptr)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
at Emgu.CV.CvInvoke..cctor()
   Exception_EndOfInnerExceptionStack
   at Emgu.CV.MatInvoke..cctor()
   Exception_EndOfInnerExceptionStack
   at Emgu.CV.Mat..ctor()

OS / Platform
Mac OS Sonoma 14.3.1

.Net version
.Net 8

CPU Architecture
ARM64

Emgu CV package used
Emgu.CV (4.8.1.5350)
Emgu.CV.Bitmap (4.8.1.5350)
Emgu.CV.runtime.maui.macos (4.8.1.5350)

This problem is occur in only Mac Platform (net8.0-maccatalyst with arm64).

Expected behavior
Emgu.CV.CvInvoke method work without any exception.

@hirendh
Copy link
Author

hirendh commented Apr 18, 2024

This issue resolved now if any one felt this issue please add below code in csproj file

<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'maccatalyst-arm64' and '$(Configuration)' == 'Release'">
		<MtouchInterpreter>-all,Emgu.CV</MtouchInterpreter>
		<MtouchInterpreter>-all,Emgu.CV.Bitmap</MtouchInterpreter>
	</PropertyGroup>

@emgucv
Copy link
Owner

emgucv commented Apr 19, 2024

Thanks for pointing that out.

This commit fix the problem too:
bbeb004

It will be included in the next release. You won't need to add the above project settings once the next release is out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants