[ Aspose.OMR ] [ Xamarin.Forms ] - System.PlatformNotSupportedException: Operation is not supported on this platform

Hello, I am trying to recognize an image with browns.omr in a Xamarin.forms application, but I am receiving an exception of error saying, “System.platformnotsupportexception: Operation is not supported on this platform.”

How can I get around this problem? Please help me.

Log:

“type”: “System.PlatformNotSupportedException”,
“message”: “Operation is not supported on this platform.”,
“stackTrace”: " at System.Drawing.Image.FromStream (System.IO.Stream stream) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/Facades/System.Drawing.Common/Stubs.cs:724
at \b\u0015\u0005.\u0002 (System.IO.Stream \u0002) [0x00000] in <4631df33c0e74db80b7b9b239680ef58>:0
at Aspose.OMR.Api.TemplateProcessor.\u0003 (\u0002\u0005\u000f \u0002, System.Int32 \u0003, System.String \u0005) [0x0001c] in <4631df33c0e74db80b7b9b239680ef58>:0
at Aspose.OMR.Api.TemplateProcessor.\u0002 (\u0002\u0005\u000f \u0002, System.Int32 \u0003, System.String \u0005) [0x00035] in <4631df33c0e74db80b7b9b239680ef58>:0
at Aspose.OMR.Api.TemplateProcessor.RecognizeImage (System.IO.MemoryStream stream, System.Int32 recognitionThreshold) [0x00014] in <4631df33c0e74db80b7b9b239680ef58>:0

Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Api.TemplateProcessor templateProcessor = omrEngine.GetTemplateProcessor(GetTemplateFile(), Encoding.Default);

My Code:

var streamImage = await CurrentFileResult.OpenReadAsync();
MemoryStream memoryStream = new MemoryStream();
streamImage.CopyTo(memoryStream);

Aspose.OMR.Model.RecognitionResult recognitionResult = templateProcessor.RecognizeImage(memoryStream);

Hello, @wilton.
Sorry to hear about it.

Can you share details about your project:

  1. Exact version Aspose.OMR for .NET.
  2. Framework implementation of Aspose.OMR for .NET.(.netstandard2.0,.net5.0,.net6.0 etc.)
  3. Xamarin version and target platforms.

Thank you!

Hello, @nikita.korobeynikov .

  1. Exact version Aspose.OMR for .NET.
    23.11.0
  2. Framework implementation of Aspose.OMR for .NET.(.netstandard2.0,.net5.0,.net6.0 etc.)
    .netstandard2.0
  3. Xamarin version and target platforms.
    Xamarin.Forms v5.0.0.2622
    Targets: Android / iOS

Thank you!

@wilton

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): OMRNET-933

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hello, @wilton

Thank you for the wait.
Please try following fixes:

  1. Install “System.Drawing.Common” NuGet package in the same project as “Aspose.OMR”.
    or
  2. Use other implementation versions (.net5.0.net6.0.net7.0) of the library.

If neither of the fixes help - we are also planning a version of Aspose.OMR with alternative drawing engine. Instead of System.Drawing it will be using Aspose.Drawing. It proved to be more dependable in non-windows platforms.

Hi, @nikita.korobeynikov

I already have the nuget “System.Drawing.Common” version 8.0.0 installed in my Xamarin.Forms project.

In this case, is there no alternative to make it work?

Hello, @wilton
I can only recommend Aspose.OMR version with Aspose.Drawing. We plan it to be published in the end of the December 2023 or start of January 2024.

I will post additional notification in this thread.

Hi, @nikita.korobeynikov

I will be waiting for the notification when this update is released. Because we paid a very high amount for the license and we will only be able to use it when it this feature released. It’s very important for us.

Happy New Year!

@wilton

Sure, we will inform you as soon as the ticket is resolved. Please spare us little time.

Hello, @wilton

Thank you for your patience!
Aspose.Drawing variation can be found here:
Downloads ---New Releases-aspose.omr-for-.net-23.12-(dlls-only;aspose.drawing)
Please share your results.

Hello, @nikita.korobeynikov

Now I can’t even get to the Recognize method, an error is already occurring when loading the template, the app is already crashing at this point:

Exception:

Could not load signature of : due to: Could not resolve type with token 01000035 from typeref (expected class ‘Aspose.Drawing.Rectangle’ in assembly ‘Aspose.Drawing, Version=23.1.0.0, Culture=neutral, PublicKeyToken =716fcc553a201e56’) assembly:Aspose.Drawing, Version=23.1.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56 type:Aspose.Drawing.Rectangle member:(null)

My code:

Aspose.OMR.Api.TemplateProcessor templateProcessor = omrEngine.GetTemplateProcessor(…, Encoding.Default);

Hello, @wilton

Sorry to hear it.
Can you share sample project (.csproj+.cs files)?

Hello, @nikita.korobeynikov

The sample project is attached

Add a license and dll to the folders:
…\AppSampleCorrector\Resources\Aspose.OMR.NET.lic
…\DLL_AsposeOMR\netstandard2.0\Aspose.OMR.dll

Just to update you, this dll you sent causes 2 errors:

1 - When trying to load the license:

System.TypeLoadException: ‘Value type instance size (1311768) cannot be zero, negative, or bigger than 1Mb’

2 - When trying to load the template:

Could not load signature of : due to: Could not resolve type with token 01000035 from typeref (expected class ‘Aspose.Drawing.Rectangle’ in assembly ‘Aspose.Drawing, Version=23.1.0.0, Culture=neutral, PublicKeyToken =716fcc553a201e56’) assembly:Aspose.Drawing, Version=23.1.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56 type:Aspose.Drawing.Rectangle member:(null)

I await your return

Xamarin.Forms_AppSampleCorrector.Android.zip (1,0,MB)

@wilton

Thanks for the information and details. We have updated the logged ticket accordingly and will inform you once we have some updates.

Hello, @wilton

I have investigated the project you provided. The problem appears to be in a unique approach at assembly resolve in Xamarin build implementations. Xamarin require full transitive dependency resolution, which are the reason for “Could not resolve” errors during build.

I have updated a sample solution with a workaround (link for archive in private messages) for Android, which I suppose can be copied for iOS also.

By adding into .csproj file next lines:

  <Target Name="ResolveFix" BeforeTargets="_ResolveAssemblies" >
	<PropertyGroup>
      <TargetFrameworkDirectory>$(TargetFrameworkDirectory);$(SolutionDir)\ResolveFix</TargetFrameworkDirectory>
	</PropertyGroup>

We are injecting into dll paths an extra folder - “ResolveFix”, which can be found in the root of the solution. Inside this folder are reference assemblies which are used during build of the solution, but do not participate in final artifacts and do not intertwine with Aspose.OMR library.
This process also does not affect the resulting .apk file.

Also, I have removed all references to Aspose.Drawing\PDF\Imaging .etc. These dependencies are meant to be internal and are not required for Aspose.OMR working process.

    <PackageReference Include="Aspose.BarCode">
      <Version>23.10.0</Version>
    </PackageReference>
    <PackageReference Include="Aspose.Drawing">
      <Version>23.12.0</Version>
    </PackageReference>
    <PackageReference Include="Aspose.Drawing.Common">
      <Version>23.12.0</Version>
    </PackageReference>
    <PackageReference Include="Aspose.Imaging">
      <Version>23.11.0</Version>
    </PackageReference>
    <PackageReference Include="Aspose.PDF">
      <Version>23.11.0</Version>
    </PackageReference>
  </ItemGroup>

This thread uncovers an important task, the solution for which we will include in the future releases.

Hello, @nikita.korobeynikov

It really solved the problem of loading the license file and template, but I’m running into another problem.

I gave you a prototype with 3 ways to read the image, through the camera, through the gallery and by opening an Embedded Resource file for the project. Only the third option works, the others give me the following error, even opening the same image from the gallery doesn’t work:

Exception:

Failed to find all reference points on image! Please make sure they are clearly visible and have enough blank space around them.

at p. ( ) [0x0004e] in <180ae9d6770546d8863d197c62d4a9a3>:0
at p. ( , ) [0x00000] in <180ae9d6770546d8863d197c62d4a9a3>:0
at p. ( , , , System.Int32 ) [0x0001b] in <180ae9d6770546d8863d197c62d4a9a3>:0
at Aspose.OMR.Api.TemplateProcessor. ( , System.Int32 , System.String ) [0x00056] in <180ae9d6770546d8863d197c62d4a9a3>:0
at Aspose.OMR.Api.TemplateProcessor. ( , System.Int32 , System.String ) [0x00035] in <180ae9d6770546d8863d197c62d4a9a3>:0
at Aspose.OMR.Api.TemplateProcessor.Recognize (System.IO.Stream stream, System.Int32 recognitionThreshold) [0x00014] in <180ae9d6770546d8863d197c62d4a9a3>:0

Hello, @wilton

I am glad to hear that hotfix is working.

From your description, it appears to be that streams passed to Recognize method are different from embedded\gallery\camera modes.
Can you extract and share images from camera\gallery before they send to Aspose.OMR Recognize method?

Hello, @nikita.korobeynikov

I’m sending the images as attachments, I noticed that the gallery image is being compressed by 75%, but it’s not losing quality, and even so aspose doesn’t read the image.

Regarding the camera, I noticed that if the photo is a little crooked, aspose won’t read the image either. I’ll test a plugin that crops the photo, leaving the document in a better position for reading.

Images:

Camera:
1 Not work
IMG_CAMERA_Not_work.jpg (253,3,KB)
2 it works
IMG_CAMERA_it _works.jpg (915,8,KB)

Gallery (Compressed) - Not work:
IMG_Compressed_Not_work.jpg (177,5,KB)

Embedded Resource - it works:
IMG_EmbeddedResource_it _works.jpg (206,2,KB)

@wilton

Thanks for providing the files. Please allow us to perform some investigation and we will let you know once we have results.

Hello, @wilton

Thank you for your patience!

I have investigated samples you provided, and I can confirm that “not_work” samples are failing at recognition because of small dimensions. Library are not suited for 600x900 scans - it is considered to be too small at the moment. Exact bottom line dimensions are hard to tell, because of difference in image quality, but I would recommend images to be at least 1200x1800.

We are planning this year a release with support for smaller scans. As a temporary workaround, I would recommend decreasing compression of images in camera.