You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to call Windows 10 UWP OCR APIs from a .NET 5 Windows Forms application. The code which i'm using was perfectly working on .NET Core 3.1 but on .NET 5 it's extremely unstable. For some reason the code throws either ObjectDisposedException or sometimes InvalidCastException. this usually happens on the call to GetSoftwareBitmapAsync() but sometimes right on the first await. Also, hen wrapped in a method, it usually works on the first run but on subsequent runs it fails as above. Here's a full code sample tested on both .NET Core 3.1 and .NET 5 with the above results.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Threading.Tasks;
namespace Supergovno
{
static class Program
{
static async Task<int> Main()
{
Bitmap Screen = new Bitmap(500, 500);
Graphics g = Graphics.FromImage(Screen);
g.CopyFromScreen(1, 1, 00, 0, Screen.Size);
Bitmap S = new Bitmap(Screen, new Size(500, 500));
var engine = Windows.Media.Ocr.OcrEngine.TryCreateFromLanguage(new Windows.Globalization.Language("en"));
using MemoryStream memoryStream = new();
S.Save(memoryStream, ImageFormat.Bmp);
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(memoryStream.AsRandomAccessStream());
var softwareBitmap = await decoder.GetSoftwareBitmapAsync();
var ocrResult = await engine.RecognizeAsync(softwareBitmap);
Console.WriteLine(ocrResult.Text);
Console.WriteLine("OK!");
Console.ReadLine();
return 0;
}
}
}
Configuration
I'm using .NET 5.0.101 on Windows 10 X64 10.0.19042.
Regression?
Yes. Everything is working on .NET Core 3.1.
Other information
The text was updated successfully, but these errors were encountered:
Description
I'm trying to call Windows 10 UWP OCR APIs from a .NET 5 Windows Forms application. The code which i'm using was perfectly working on .NET Core 3.1 but on .NET 5 it's extremely unstable. For some reason the code throws either ObjectDisposedException or sometimes InvalidCastException. this usually happens on the call to GetSoftwareBitmapAsync() but sometimes right on the first await. Also, hen wrapped in a method, it usually works on the first run but on subsequent runs it fails as above. Here's a full code sample tested on both .NET Core 3.1 and .NET 5 with the above results.
Configuration
I'm using .NET 5.0.101 on Windows 10 X64 10.0.19042.
Regression?
Yes. Everything is working on .NET Core 3.1.
Other information
The text was updated successfully, but these errors were encountered: