x86 Uygulamalarda OcrInternals Dağıtım Hatası

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronTesseract.ReadScreenShot(), yalnızca bir Windows x64 sürecinde desteklenen IronOCR'un AdvancedScan hattı üzerinden çalışır. x86 bir uygulamadan çağırmak OcrInternals dağıtım hatasıyla başarısız olur, IronOcr.Extensions.AdvancedScan paketi yüklendiğinde bile.

Error while reading a screenshot, Error while deploying OcrInternals for IronOcr:
'Unable to locate 'OcrInternals' in
...\bin\Debug\runtimes\win-x86\native,
...\bin\Debug\runtimes\win.6.2-x86\native,
...\bin\Debug\runtimes\win.6-x86\native,
...\bin\Debug\,
...
nor in an embedded resource.'
Please install the NuGet Package 'IronOcr.Extension.AdvancedScan' when using IronOcr on Windows.
[Issue Code IRONOCR-OCRINTERNALS-DEPLOYMENT-ERROR-WIN]

Hata, ReadScreenShot() çağrısının kendisinde ortaya çıkar:

var ocr = new IronOcr.IronTesseract();
using (var input = new IronOcr.OcrInput())
{
    input.LoadImage("Step_1-5.jpg");
    var result = ocr.ReadScreenShot(input);
    Console.WriteLine(result.Text);
}
var ocr = new IronOcr.IronTesseract();
using (var input = new IronOcr.OcrInput())
{
    input.LoadImage("Step_1-5.jpg");
    var result = ocr.ReadScreenShot(input);
    Console.WriteLine(result.Text);
}
Imports IronOcr

Dim ocr As New IronTesseract()
Using input As New OcrInput()
    input.LoadImage("Step_1-5.jpg")
    Dim result = ocr.ReadScreenShot(input)
    Console.WriteLine(result.Text)
End Using
$vbLabelText   $csharpLabel

ReadScreenShot()'nin bağımlı olduğu AdvancedScan yerel bileşenleri, bir x86 sürecinde desteklenmez. IronOcr.Extensions.AdvancedScan yüklenmesi gereklidir, ancak bu, host sürecin bitliğini değiştirmez, bu yüzden çağrı hâlâ x86 altında çalışamaz.

DikkatAdvancedScan'i kurmak ReadScreenShot()'ı x86 prosesinde çalıştırmaz. Onu çağıran prosesin x64 olarak çalışması gerekir.

Çözüm

Seçenek 1: Doğrudan x64'a Hedefleyin

En temiz çözüm, projenin platform hedefini doğrudan x64'e değiştirmektir. Visual Studio'da:

  1. Projeye sağ tıklayın ve Properties seçin.
  2. Build sekmesini açın.
  3. Platform hedefini x64 olarak ayarlayın.
  4. 32-bit Tercih Etme seçeneğini kaldırın.
  5. Tekrar derleyin ve çalıştırın.

Host süreç x64 olarak çalıştığında, ReadScreenShot() desteklenen bir ortamda çalışır.

Seçenek 2: Uygulamayı x86 Tutun ve x64 Bir Yardımcı Proses Çağırın

Ana uygulama x86 kalmalı olduğunda, yalnızca OCR işlemini küçük bir x64 yardımcı işleme taşıyın ve mevcut uygulamadan çağırın. Yapı şu şekilde görünür:

MainWinForms.x86
  - .NET Framework Windows Forms app
  - Platform target: x86
  - Does not run ReadScreenShot() directly
  - Calls the x64 helper process
OcrHelper.x64
  - .NET Framework Console app
  - Platform target: x64
  - References IronOCR
  - References IronOcr.Extensions.AdvancedScan
  - Runs Ocr.ReadScreenShot()
  - Returns the OCR result to the main app

x86 uygulaması dokunulmadan kalırken AdvancedScan desteklenen yerde çalışır.

x86 uygulamasından yardımı çağırma

Yardımcıyı ProcessStartInfo ile başlatın ve çıktısını okuyun:

using System;
using System.Diagnostics;
using System.IO;
public static class OcrHelperClient
{
    public static string ReadScreenshotWithHelper(string imagePath)
    {
        string helperExePath = Path.Combine(
            AppDomain.CurrentDomain.BaseDirectory,
            "OcrHelper.x64",
            "OcrHelper.x64.exe"
        );
        if (!File.Exists(helperExePath))
        {
            throw new FileNotFoundException("The OCR helper executable was not found.", helperExePath);
        }
        var startInfo = new ProcessStartInfo
        {
            FileName = helperExePath,
            Arguments = "\"" + imagePath + "\"",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            CreateNoWindow = true
        };
        using (var process = new Process())
        {
            process.StartInfo = startInfo;
            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            string error = process.StandardError.ReadToEnd();
            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                throw new Exception("OCR helper failed: " + error);
            }
            return output;
        }
    }
}
using System;
using System.Diagnostics;
using System.IO;
public static class OcrHelperClient
{
    public static string ReadScreenshotWithHelper(string imagePath)
    {
        string helperExePath = Path.Combine(
            AppDomain.CurrentDomain.BaseDirectory,
            "OcrHelper.x64",
            "OcrHelper.x64.exe"
        );
        if (!File.Exists(helperExePath))
        {
            throw new FileNotFoundException("The OCR helper executable was not found.", helperExePath);
        }
        var startInfo = new ProcessStartInfo
        {
            FileName = helperExePath,
            Arguments = "\"" + imagePath + "\"",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            CreateNoWindow = true
        };
        using (var process = new Process())
        {
            process.StartInfo = startInfo;
            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            string error = process.StandardError.ReadToEnd();
            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                throw new Exception("OCR helper failed: " + error);
            }
            return output;
        }
    }
}
Imports System
Imports System.Diagnostics
Imports System.IO

Public Module OcrHelperClient
    Public Function ReadScreenshotWithHelper(imagePath As String) As String
        Dim helperExePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "OcrHelper.x64", "OcrHelper.x64.exe")
        If Not File.Exists(helperExePath) Then
            Throw New FileNotFoundException("The OCR helper executable was not found.", helperExePath)
        End If

        Dim startInfo As New ProcessStartInfo With {
            .FileName = helperExePath,
            .Arguments = """" & imagePath & """",
            .UseShellExecute = False,
            .RedirectStandardOutput = True,
            .RedirectStandardError = True,
            .CreateNoWindow = True
        }

        Using process As New Process()
            process.StartInfo = startInfo
            process.Start()
            Dim output As String = process.StandardOutput.ReadToEnd()
            Dim error As String = process.StandardError.ReadToEnd()
            process.WaitForExit()

            If process.ExitCode <> 0 Then
                Throw New Exception("OCR helper failed: " & error)
            End If

            Return output
        End Using
    End Function
End Module
$vbLabelText   $csharpLabel

Hem StandardOutput hem de StandardError yönlendirilmesi, çağıranın tanınan metni yakalamasına ve yardımcının çıkış kodundan herhangi bir hatayı ortaya çıkarmasına olanak tanır.

string imagePath = @"C:\Images\Step_1-5.jpg";
string text = OcrHelperClient.ReadScreenshotWithHelper(imagePath);
Console.WriteLine(text);
string imagePath = @"C:\Images\Step_1-5.jpg";
string text = OcrHelperClient.ReadScreenshotWithHelper(imagePath);
Console.WriteLine(text);
Imports System

Dim imagePath As String = "C:\Images\Step_1-5.jpg"
Dim text As String = OcrHelperClient.ReadScreenshotWithHelper(imagePath)
Console.WriteLine(text)
$vbLabelText   $csharpLabel

x64 Yardımcısını Oluşturma

IronOcr ve IronOcr.Extensions.AdvancedScan referans alan bir x64 konsol uygulaması olarak yardımcıyı oluşturun. İlk argümandan görüntü yolunu okur, OCR çalıştırır ve sonucu stdout yazar:

using System;
using System.IO;
using IronOcr;
namespace OcrHelper.x64
{
    internal static class Program
    {
        private static int Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    Console.Error.WriteLine("Missing image path argument.");
                    return 1;
                }
                string imagePath = args[0];
                if (!File.Exists(imagePath))
                {
                    Console.Error.WriteLine("Image file was not found: " + imagePath);
                    return 2;
                }
                string licenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE_KEY");
                if (!string.IsNullOrWhiteSpace(licenseKey))
                {
                    License.LicenseKey = licenseKey;
                }
                var ocr = new IronTesseract();
                using (var input = new OcrInput())
                {
                    input.LoadImage(imagePath);
                    var result = ocr.ReadScreenShot(input);
                    Console.WriteLine(result.Text);
                }
                return 0;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return 99;
            }
        }
    }
}
using System;
using System.IO;
using IronOcr;
namespace OcrHelper.x64
{
    internal static class Program
    {
        private static int Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    Console.Error.WriteLine("Missing image path argument.");
                    return 1;
                }
                string imagePath = args[0];
                if (!File.Exists(imagePath))
                {
                    Console.Error.WriteLine("Image file was not found: " + imagePath);
                    return 2;
                }
                string licenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE_KEY");
                if (!string.IsNullOrWhiteSpace(licenseKey))
                {
                    License.LicenseKey = licenseKey;
                }
                var ocr = new IronTesseract();
                using (var input = new OcrInput())
                {
                    input.LoadImage(imagePath);
                    var result = ocr.ReadScreenShot(input);
                    Console.WriteLine(result.Text);
                }
                return 0;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return 99;
            }
        }
    }
}
Imports System
Imports System.IO
Imports IronOcr

Namespace OcrHelper.x64
    Friend Module Program
        Private Function Main(args As String()) As Integer
            Try
                If args.Length = 0 Then
                    Console.Error.WriteLine("Missing image path argument.")
                    Return 1
                End If

                Dim imagePath As String = args(0)
                If Not File.Exists(imagePath) Then
                    Console.Error.WriteLine("Image file was not found: " & imagePath)
                    Return 2
                End If

                Dim licenseKey As String = Environment.GetEnvironmentVariable("IRONOCR_LICENSE_KEY")
                If Not String.IsNullOrWhiteSpace(licenseKey) Then
                    License.LicenseKey = licenseKey
                End If

                Dim ocr As New IronTesseract()
                Using input As New OcrInput()
                    input.LoadImage(imagePath)
                    Dim result = ocr.ReadScreenShot(input)
                    Console.WriteLine(result.Text)
                End Using

                Return 0
            Catch ex As Exception
                Console.Error.WriteLine(ex.ToString())
                Return 99
            End Try
        End Function
    End Module
End Namespace
$vbLabelText   $csharpLabel

Farklı çıkış kodları (1, 2, 99), çağıran uygulamanın eksik bir argümanı eksik bir dosya veya beklenmeyen bir istisnadan ayırt etmesine olanak tanır.

Üretim Kullanımı İçin Notlar

Örnek, sadelik için stdout kullanır. Üretim için, mimarinize uyan iletişim yöntemini seçin. Seçenekler şunları içerir:

  • Standart çıkış ve standart hata.
  • Geçici JSON dosyaları.
  • Adlandırılmış borular.
  • Yerel bir HTTP uç noktası.
  • x64 OCR işlemini barındıran bir Windows Hizmeti.

Küçük veya arada çağrılar için: yardımı talep üzerine başlatmak genellikle iyidir. Yüksek hacimli iş yükleri için: her istek başına bir proses başlatmaktan daha verimli olma eğiliminde olan uzun süreli bir x64 yardımcı hizmeti genellikle daha iyidir.

Hata Ayıklama İpuçları

Yardımcı yaklaşım kötü davranış gösterdiğinde şu kontrolleri gerçekleştirin:

  • Ana uygulamanın gerçekten x86 kalması gerektiğini ve Ocr.Read()'nın ekran görüntüsü senaryosu için yeterli olmadığını doğrulayın.
  • ReadScreenShot()'nin doğrudan bir x64 sürecinden çalıştırıldığında başarılı olduğunu doğrulayın.
  • Yardımcı proje için Platform hedefi: x64 ile oluşturun ve x86 uygulamanın hiçbir zaman ReadScreenShot()'yi kendisinin çağırmadığından emin olun.
  • x64 yardımcı projede IronOcr.Extensions.AdvancedScan yükleyin.
  • Yardımcı işlemin erişebileceği görüntü yolunun yardımcıya geçirildiğini kontrol edin.
  • IronOCR lisans anahtarını kodda, uygulama konfigürasyonunda veya IRONOCR_LICENSE_KEY ortam değişkeninde yapılandırın.

Yardımcıyı yayınlarken, yalnızca .exe değil, tüm derleme çıktısını kopyalayın. Çıkış klasörü, tüm referans verilen bileşenleri ve yapıyla üretilen doğal çalışma zamanı dosyalarını içermelidir, aksi takdirde yardımcı aynı dağıtım hatasıyla karşılaşır.

Curtis Chau
Teknik Yazar

Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapı...

Daha Fazla Oku
Başlamaya Hazır mısınız?
Nuget İndirmeler 6,136,090 | Sürüm: 2026.7 yeni yayınlandı
Still Scrolling Icon

Hâlâ Kaydırıyor Musunuz?

Hızlıca kanıt ister misiniz? PM > Install-Package IronOcr
örnek çalıştır görüntünüzün aranabilir metin haline gelmesini izleyin.