System.Memory Version Conflict in IronOCR on .NET Framework
On IronOCR versions prior to v2026.4.1 on the .NET Framework, calling IronTesseract().Read() can crash with a System.Memory exception and return empty OCR results just before the failure.
v2026.4.1. Upgrade to that version for the permanent fix. This article is for users still on earlier versions.System.Reflection.TargetInvocationException (mscorlib.dll)
"Exception has been thrown by the target of an invocation"
The crash comes from a version conflict between two System.Memory assemblies loaded into the same application. It shows up even in clean projects and is often preceded by a build warning like:
Found conflicts between different versions of "System.Memory"...
"System.Memory, Version=4.0.1.2" was chosen because it was primary and "System.Memory, Version=4.0.2.0" was not.
Affected versions: 2025.4.4, 2025.9.4, 2025.5.6, 2025.6.8. Resolved in 2026.4.1.
Solution
1. Add a binding redirect
Add an explicit binding redirect to your application's App.config so the runtime always loads the System.Memory version IronOCR expects:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="4.0.2.0" newVersion="4.0.1.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The redirect forces your application onto System.Memory version 4.0.1.2, which stops the crash and restores correct OCR behavior.
Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.