System.IO.FileLoadException: Could not load file or assembly 'log4net


We are using Crystal Report In MVC.NET project refer to this link : to create a PDF file from the data and export it using Crystal Reports in MVC.NET.

we have this error after exporting report and try to run it : System.TypeInitializationException: The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


2 Answers


Most likely, you compiled the app using 'AnyCPU' as the target. Change to a specific target (x86 or 64). Ensure the Crystal runtime matches that target. Ensure the web app pool is also set for that target.

answered on Stack Overflow Jun 22, 2020 by MilletSoftware

This is what worked for me:

Make note of some details

From the error, record the: .dll file Version PublicKeyToken for later use.

Confirm that the .dll exists

Find the project in VS, right click and “Open Folder in File Explorer”. Then go into ../bin/Debug and search for the .dll file that is causing the exception.

If the .dll doesn’t exist then this is not the correct fix and something else is awry.

Get the correct assembly version the .dll is using

The version in my .dll was If you do not already have ILSpy installed, open the microsoft store on your PC and download it (it’s free). Then drag the .dll file in question into ILSpy and search for the line that reads:

[assembly: AssemblyVersion("")]

As you can see, there is an incongruence between the versions. This is what is causing the error.

Update app.config

Back in VisualStudio, open the app.config file in the failing project and add this snippet within :

   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <assemblyIdentity name="System.Configuration.ConfigurationManager" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
       <bindingRedirect oldVersion="" newVersion="" />

Ensure that the publicKeyToken is the value you recorded and that you set the oldVersion upper range value and the newVersion value to the assemblyVersion found in the .dll file. Also, make sure that the version shown in the error is within the range that you’re setting (i.e. it is an older version).

All set. This should work.

answered on Stack Overflow Jun 29, 2020 by Itamar Shuval

User contributions licensed under CC BY-SA 3.0