Why do I get an "System.IO.FileLoadException: Could not load file or assembly" error?

In my .NET project I get an "System.IO.FileLoadException: Could not load file or assembly" error. What could be causing this?

28th October 2019
ian.morris

In my .NET project I get an "System.IO.FileLoadException: Could not load file or assembly" error. What could be causing this?

This is probably because you have an strong-named assembly which has not been redirected. iText 7 has add-ons which can be released separately from releases of the core library, and so may contain references to a different version of the library than the one you are using.

Fortunately, a feature was introduced in .NET Framework 4.5.1 called Automatic Binding Redirect Generation which can automatically resolve this issue. As of .NET 4.5.1 binding redirection should work out of the box, and Visual Studio will usually add the required lines to your project file even for earlier versions. However, depending on your project or your Visual Studio settings this feature may be turned off, so you may need to add them manually.

If you're using strong-named assemblies, check if the following lines exist in your project file (.csproj). If they do not exist, try adding them to resolve the FileLoadException error:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> 
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>

By setting these two flags, your project should now load the correct iText library version.

We hope this information has been helpful.



문의

문의가 해결되지 않았습니까? 

저희가 도와드리겠습니다. 연락해 주시면 빠르게 답변해 드리겠습니다.

문의하기
최신 정보를 받아보세요

11,000명 이상의 가입자와 함께 새로운 제품, 업데이트, 팁, 기술 솔루션 및 기회에 대한 최신 정보를 받아보시면서 iText PDF 전문가가 되어보세요.

지금 구독하기