# Erro de Implantação do OcrInternals em Aplicativos x86
`IronTesseract.ReadScreenShot()` roda pelo pipeline AdvancedScan do IronOCR, que é suportado apenas em um processo Windows x64. Chamando-o de um aplicativo x86 falha com um erro de implantação `OcrInternals`, mesmo quando o pacote `IronOcr.Extensions.AdvancedScan` está instalado.
```txt
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]
```
A falha surge na própria chamada `ReadScreenShot()`:
```csharp
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);
}
```
Os componentes nativos AdvancedScan dos quais `ReadScreenShot()` depende não são suportados dentro de um processo x86. Instalar `IronOcr.Extensions.AdvancedScan` é necessário, mas isso não altera a arquitetura do processo host, então a chamada ainda não pode ser executada em x86.
[[e:(Instalar AdvancedScan não faz com que ReadScreenShot() funcione em um processo x86. O processo que o chama deve ser executado como x64.)]]
## Solução
### Opção 1: Direcionar para x64 diretamente
A correção mais limpa é mudar o alvo de plataforma do projeto para x64. No Visual Studio:
1. Clique com o botão direito no projeto e selecione **Propriedades**.
2. Abra a aba **Compilação**.
3. Defina **Alvo da plataforma** para **x64**.
4. Desmarque **Preferir 32 bits**.
5. Recompile e execute.
Com o processo host rodando como x64, `ReadScreenShot()` executa em um ambiente suportado.
### Opção 2: Mantenha o aplicativo x86 e chame um processo auxiliar x64
Quando o aplicativo principal deve permanecer x86, mova apenas a operação OCR para um pequeno processo auxiliar x64 e chame-o do aplicativo existente. A estrutura se parece com isto:
```txt
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
```
O aplicativo x86 permanece inalterado enquanto o AdvancedScan roda onde é suportado.
#### Chamando o auxiliar do aplicativo x86
Inicie o auxiliar com `ProcessStartInfo` e leia sua saída:
```csharp
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;
}
}
}
```
Redirecionar tanto `StandardOutput` quanto `StandardError` permite que o chamador capture o texto reconhecido e apresente qualquer falha a partir do código de saída do auxiliar.
```csharp
string imagePath = @"C:\Images\Step_1-5.jpg";
string text = OcrHelperClient.ReadScreenshotWithHelper(imagePath);
Console.WriteLine(text);
```
#### Construindo o auxiliar x64
Construa o auxiliar como um aplicativo de console x64 que referencia `IronOcr` e `IronOcr.Extensions.AdvancedScan`. Lê o caminho da imagem do primeiro argumento, executa o OCR e grava o resultado em `stdout`:
```csharp
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;
}
}
}
}
```
Códigos de saída distintos (`1`, `2`, `99`) permitem que o aplicativo chamador diferencie entre um argumento ausente, um arquivo ausente ou uma exceção inesperada.
## Notas para Uso em Produção
O exemplo usa `stdout` por simplicidade. Para produção, escolha o método de comunicação que se adequa à sua arquitetura. As opções incluem:
- Saída padrão e erro padrão.
- Arquivos JSON temporários.
- Pipes nomeados.
- Um endpoint HTTP local.
- Um serviço Windows hospedando a operação OCR x64.
**Para chamadas pequenas ou ocasionais:** lançar o auxiliar sob demanda geralmente está bem. **Para cargas de trabalho de alto volume:** um serviço auxiliar x64 de longa execução tende a ser mais eficiente do que iniciar um processo por solicitação.
## Dicas de Depuração
Realize estas verificações quando a abordagem auxiliar se comportar mal:
- Confirme que o aplicativo principal realmente precisa permanecer x86, e que `Ocr.Read()` não é suficiente para o cenário de captura de tela.
- Verifique se `ReadScreenShot()` é bem-sucedido quando executado diretamente de um processo x64.
- Construa o projeto auxiliar com **Plataforma alvo: x64**, e certifique-se de que o aplicativo x86 nunca chame `ReadScreenShot()` por si só.
- Instale `IronOcr.Extensions.AdvancedScan` no projeto auxiliar x64.
- Verifique se o caminho da imagem passado para o auxiliar é acessível pelo processo auxiliar.
- Configure a chave de licença do IronOCR no código, configuração do aplicativo ou na variável de ambiente `IRONOCR_LICENSE_KEY`.
Ao publicar o auxiliar, copie todo o resultado da construção, não apenas o `.exe`. A pasta de saída deve incluir todas as assemblies referenciadas e os arquivos de runtime nativo gerados pela construção, ou o auxiliar enfrentará o mesmo erro de implantação.
IronTesseract.ReadScreenShot() roda pelo pipeline AdvancedScan do IronOCR, que é suportado apenas em um processo Windows x64. Chamando-o de um aplicativo x86 falha com um erro de implantação OcrInternals, mesmo quando o pacote IronOcr.Extensions.AdvancedScan está instalado.
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]
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]
Text
A falha surge na própria chamada ReadScreenShot():
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);
}
C#
Os componentes nativos AdvancedScan dos quais ReadScreenShot() depende não são suportados dentro de um processo x86. Instalar IronOcr.Extensions.AdvancedScan é necessário, mas isso não altera a arquitetura do processo host, então a chamada ainda não pode ser executada em x86.
Cuidado: Instalar AdvancedScan não faz com que ReadScreenShot() funcione em um processo x86. O processo que o chama deve ser executado como x64.
Solução
Opção 1: Direcionar para x64 diretamente
A correção mais limpa é mudar o alvo de plataforma do projeto para x64. No Visual Studio:
Clique com o botão direito no projeto e selecione Propriedades.
Abra a aba Compilação.
Defina Alvo da plataforma para x64.
Desmarque Preferir 32 bits.
Recompile e execute.
Com o processo host rodando como x64, ReadScreenShot() executa em um ambiente suportado.
Opção 2: Mantenha o aplicativo x86 e chame um processo auxiliar x64
Quando o aplicativo principal deve permanecer x86, mova apenas a operação OCR para um pequeno processo auxiliar x64 e chame-o do aplicativo existente. A estrutura se parece com isto:
MainWinForms.x86 - .NET Framework Windows Forms app - Platform target: x86 - Does not run ReadScreenShot() directly - Calls the x64 helper processOcrHelper.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
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
Text
O aplicativo x86 permanece inalterado enquanto o AdvancedScan roda onde é suportado.
Chamando o auxiliar do aplicativo x86
Inicie o auxiliar com ProcessStartInfo e leia sua saída:
using System;using System.Diagnostics;using System.IO;public static class OcrHelperClient{ public static stringReadScreenshotWithHelper(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;
}
}
}
C#
Redirecionar tanto StandardOutput quanto StandardError permite que o chamador capture o texto reconhecido e apresente qualquer falha a partir do código de saída do auxiliar.
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);
C#
Construindo o auxiliar x64
Construa o auxiliar como um aplicativo de console x64 que referencia IronOcr e IronOcr.Extensions.AdvancedScan. Lê o caminho da imagem do primeiro argumento, executa o OCR e grava o resultado em stdout:
using System;using System.IO;using IronOcr;namespace OcrHelper.x64{ internal static class Program { private static intMain(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;
}
}
}
}
C#
Códigos de saída distintos (1, 2, 99) permitem que o aplicativo chamador diferencie entre um argumento ausente, um arquivo ausente ou uma exceção inesperada.
Notas para Uso em Produção
O exemplo usa stdout por simplicidade. Para produção, escolha o método de comunicação que se adequa à sua arquitetura. As opções incluem:
Saída padrão e erro padrão.
Arquivos JSON temporários.
Pipes nomeados.
Um endpoint HTTP local.
Um serviço Windows hospedando a operação OCR x64.
Para chamadas pequenas ou ocasionais: lançar o auxiliar sob demanda geralmente está bem. Para cargas de trabalho de alto volume: um serviço auxiliar x64 de longa execução tende a ser mais eficiente do que iniciar um processo por solicitação.
Dicas de Depuração
Realize estas verificações quando a abordagem auxiliar se comportar mal:
Confirme que o aplicativo principal realmente precisa permanecer x86, e que Ocr.Read() não é suficiente para o cenário de captura de tela.
Verifique se ReadScreenShot() é bem-sucedido quando executado diretamente de um processo x64.
Construa o projeto auxiliar com Plataforma alvo: x64, e certifique-se de que o aplicativo x86 nunca chame ReadScreenShot() por si só.
Instale IronOcr.Extensions.AdvancedScan no projeto auxiliar x64.
Verifique se o caminho da imagem passado para o auxiliar é acessível pelo processo auxiliar.
Configure a chave de licença do IronOCR no código, configuração do aplicativo ou na variável de ambiente IRONOCR_LICENSE_KEY.
Ao publicar o auxiliar, copie todo o resultado da construção, não apenas o .exe. A pasta de saída deve incluir todas as assemblies referenciadas e os arquivos de runtime nativo gerados pela construção, ou o auxiliar enfrentará o mesmo erro de implantação.
Curtis Chau é bacharel em Ciência da Computação (Universidade Carleton) e se especializa em desenvolvimento front-end, com experiência em Node.js, TypeScript, JavaScript e React. Apaixonado por criar interfaces de usuário intuitivas e esteticamente agradáveis, Curtis gosta de trabalhar com frameworks modernos e criar manuais bem estruturados e visualmente atraentes.