Application works fine on our laptops but running on our VMWare windows 2019 and 2022 servers we have an exception occuring when executing:
var result = ocr.Recognize(input);
Need help determing why it wont run on our VMware Aria Automation Windows Servers. I have included the entire procedure that does the OCR on the image.
public PdfHeaderInfo ExtractHeader(string pdfPath)
{
if (string.IsNullOrWhiteSpace(pdfPath))
throw new ArgumentException("PDF path is required.", nameof(pdfPath));
if (!File.Exists(pdfPath))
throw new FileNotFoundException("PDF file not found.", pdfPath);
Log($"OCR starting for: {pdfPath}");
var pdf = new Document(pdfPath);
if (pdf.Pages.Count < 1)
throw new Exception("PDF does not contain any pages.");
Log($"PDF page count: {pdf.Pages.Count}");
var device = new PngDevice(new Resolution(300));
using var fullStream = new MemoryStream();
device.Process(pdf.Pages[1], fullStream);
fullStream.Position = 0;
using var fullImage = DrawingImage.FromStream(fullStream);
using var bitmap = new DrawingBitmap(fullImage);
Log($"Rendered first page image size: {bitmap.Width}x{bitmap.Height}");
// Save rendered page for debugging
var debugDir = Path.GetDirectoryName(pdfPath) ?? Environment.CurrentDirectory;
var debugImagePath = Path.Combine(
debugDir,
Path.GetFileNameWithoutExtension(pdfPath) + "_ocr_input.png");
try
{
Directory.CreateDirectory(debugDir);
bitmap.Save(debugImagePath, ImageFormat.Png);
Log($"Saved OCR input image: {debugImagePath}");
}
catch (Exception ex)
{
Log($"WARNING: Could not save OCR input image: {ex.Message}");
}
using var imageStream = new MemoryStream();
bitmap.Save(imageStream, ImageFormat.Png);
imageStream.Position = 0;
var ocr = new AsposeOcr();
var input = new OcrInput(InputType.SingleImage);
input.Add(imageStream);
Log("Calling Aspose OCR...");
var result = ocr.Recognize(input);
var rawText = string.Join(Environment.NewLine, result.Select(r => r.RecognitionText));
Log("OCR raw text:");
Log(rawText);
var header = ParseHeader(rawText);
Log($"OCR parsed => DocumentNo='{header.DocumentNo}', Revision='{header.Revision}', CageCode='{header.CageCode}', PartNumber='{header.PartNumber}'");
return header;
}
Below is the exception we are getting.
[2026-06-22 13:53:07] [OCR] Calling Aspose OCR…
[2026-06-22 13:53:09] [2026-06-22 13:53:09] [828d5d9e3dc948edb39d1162c80f7a4f_EM-FA-K1933_Rev_NEW] OCR fallback failed: System.TypeInitializationException: The type initializer for ‘Microsoft.ML.OnnxRuntime.NativeMethods’ threw an exception.
—> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.ML.OnnxRuntime.NativeMethods…cctor()
— End of inner exception stack trace —
at Microsoft.ML.OnnxRuntime.SessionOptions…ctor()
at
↨↨.
()
at
↨↨.
.
()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at System.Lazy1.get_Value()
at
↨↨.
(DetectAreasMode
, Func`1)
at
↨↨.
(DetectAreasMode
)
at ☼§→…ctor(RecognitionSettings
, ☼←,
↨↨
)
at Aspose.OCR.AsposeOcr.Recognize(OcrInput images, RecognitionSettings settings)
at Aspose.OCR.AsposeOcr.Recognize(OcrInput images)
at AssemblyInstructionsExtract.Services.AssemblyInstructionOcrService.ExtractHeader(String pdfPath) in \AssemblyInstructionsExtract\Services\ExtractionService.cs:line 77
I have attached a screen shot of our available servers available C++ redistributable.
Screenshot 2026-06-22 140001.png (104.1 KB)