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=22.214.171.124, 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)
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 126.96.36.199. 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:
As you can see, there is an incongruence between the versions. This is what is causing the error.
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-188.8.131.52" newVersion="184.108.40.206" /> </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.
User contributions licensed under CC BY-SA 3.0