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

0

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.https://www.c-sharpcorner.com/article/use-crystal-report-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=1.2.10.0, 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)

crystal-reports

2 Answers

0

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
0

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 4.0.1.0. 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("4.0.3.0")]

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 :

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

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