システムメモリ例外
開発者が .NET Framework 上で IronOCR の最新バージョンを使用する場合、以下に示すように、プログラムの実行により System.Memory Exception が発生することがあります。
Could not load file or assembly 'System.Memory, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
この問題は IronOCR 自体に直接関係するものではありませんが、System.Memory の依存関係に関する互換性の問題が知られています。 System.Memory の新しいバージョン (例: 4.4.5 以降) が別の依存関係の一部として、または直接参照としてインストールされている場合でも、ランタイムはバージョン関連のエラーをスローする可能性があります。
これは、一部の依存関係が厳密なバージョン バインディングを強制し、理論的に互換性のある新しいバージョンが存在するかどうかに関係なく、特定のバージョンの System.Memory を必要とするために発生します。 その結果、以下に説明する回避策を適用しない限り、エラーは解決されません。
解決策
この例外の解決策は、App.config を以下のコードに置き換えることです。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
説明
変更された App.Config は、複数の依存関係が同じアセンブリの異なるバージョンを必要とする場合に発生しうるバージョン競合を防ぐことを目的としています。 この設定を使用することで、アプリケーションは実行時に適切なバージョンを読み込みます。リダイレクトにより、すべてのコンポーネントがバージョン v4.0.1.2 を使用するよう強制されるため、前述の例外が発生する可能性が排除されます。 App.Config を修正した後、アプリケーションを再実行し、プログラムが別の例外を発生させないことを確認してください。
このトピックに関する詳細情報とディスカッションについては、例外と現在の回避策の詳細が記載されているGitHub ページをご覧ください。

