'The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception
I am deploying a desktop application to my clients that uses the Crystal Reports API to display and print forms. I am building my installer using InstallShield 2012. I have also included the .NET 4.0 Framework along with all of the Crystal assemblies. I have 2 (kinda related) concerns:
1) Whenever I tried to run the application on the client machine, I get the following error:
The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument'
threw an exception.
I have no idea what I am forgetting here. The CrystalDecisions.CrystalReports.Engine dll is being registered in the GAC correctly, as are about 10 other Crystal assemblies.
2) I have asked this question on the SAP forums, and I was told I needed to include the .NET 2.0 Framework along with the .NET 4.0 Framework. I tried including the .NET 2.0 redistributable in my installer package, but the installer does not install it. Does the installer see that I have 4.0 installed, so it skips the 2.0 installation?
Solution 1:[1]
Here is what worked for me:
If you are installing on a 64-bit machine, make sure the application properties under the Build tab have "Any CPU" as the platform target, and unselect the check box for "Prefer 32-bit" if you have the option. Crystal is very touchy about 32/64 bit assemblies, and makes some pretty counterintuitive assumptions which are very difficult to troubleshoot.
Solution 2:[2]
I had similar message and after several searches online and doing all suggestions, nothing helped. Finally I found the solution. In my IIS server, under the application pool advance option, there is an option for "Enable 32-Bit Applications" - that was changed from false to true and after restarting IIS server, My program started generating pdf files.
Solution 3:[3]
Check the properties of your projectm the platform target. Install the corresponding version of Crystal Reports:
To x86 > CRforVS_redist_install_32bit
To x64 > CRforVS_redist_install_64bit
Solution 4:[4]
Solution 5:[5]
The inner exception of bug says Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304'
Changing the AppPool setting False for Enable 32-bit Application solved the issue
Solution 6:[6]
The same scenario, the application works fine in developer machine but when deployed it is throwing the exception "crystaldecisions.crystalreports.engine.reportdocument threw an exception" Details: sys.io.filenotfoundexcep crystaldecisions.reportappserver.commlayer version 13.0.2000 is missing
My IDE: MS VS 2010 Ultimate, CR V13.0.10
Solution:
I set x86 for my application, then I set x64 for my setup application
Prerequisite: I Placed the supporting CR runtime file CRRuntime_32bit_13_0_10.msi, CRRuntime_64bit_13_0_10.msi in the following directory C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\Crystal Reports for .NET Framework 4.0
Include merge module file to the setup project. Here is version is not serious thing because I use 13.0.10 soft, 13.0.16 merge module file File I included: CRRuntime_13_0_16.msm This file is found one among the set msm files.
While installing this Merge module will add the necessary DLL in the following dir C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet
DLL file version will not cause any issues.
In your developer machine you confirm it same.
Solution 7:[7]
As "M.A. Hanin" said above, it can caused by an InnerException like this:
"Unrecognized configuration section userSettings. (C:\Users\Pourakbar.h\AppData\Local\Accounting\Accounting.vshost.exe_Url_a4h1gnabohiu4wgiejk0d21rc2kbwr4g\1.0.0.0\user.config line 3)"
and I deleted the folder: C:\Users\Pourakbar.h\AppData\Local\Accounting\Accounting.vshost.exe_Url_a4h1gnabohiu4wgiejk0d21rc2kbwr4g from my computer and that worked for me!
Solution 8:[8]
I was not getting the error on 32-bit machines but was on 64-bit so I changed the target platform from x86 to Any CPU and it resolved the issue.
Solution 9:[9]
The type initializer for CrystalDecisions.CrystalReports.Engine.ReportDocument
threw an exception.
I changed the target platform from x86 to Any CPU and it resolved the issue.
Solution 10:[10]
I got a problem The type Initializer.. my config file resolved it..
i forgot to have a connection element like this
"connectionStrings"
"/connectionStrings"
maybe it depends on what you did in a code. my error is i cant open a class because of this connection element.
Solution 11:[11]
Download cr redist 2005 or 2008(which is your tool) or copy from C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\CrystalReports
Download c++ redist 2005 or 2008(which is your tool)
Install both and restart your system
Problem solved.
Solution 12:[12]
This is because of lack of Capability .... If you see the Inner Exception you will see this message
"Access is denied.
Access to speech functionality requires ID_CAP_SPEECH_RECOGNITION to be defined in the manifest."
So to get rid of this exception. turn on the capability for Speech Recognition from the Manifest file.
I had the same problem, and It solved my Problem. :)
Solution 13:[13]
What did the trick for me was to change the target machine from “ANY CPU” to “x64” or maybe in your case “x86” depending in your target machine’s architecture. I would try this first before moving into a more complex solution which indicates a more complex problem.
Solution 14:[14]
I had a similar error recently with the log4net error:
Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304'
This was on a 64bit machine but I'd only installed the 32bit runtime.
Making sure the build was targeting only x86 worked for me.
Solution 15:[15]
I had the same problem and I solved it installing both crystal Report Runtime 32 and 64 bit both version
Solution 16:[16]
Project Properties -> Compile -> Target CPU -> Any CPU And uncheck Prefer 32 bit
Done
Solution 17:[17]
-The most accurate Crystal Report Versions -Crystal report applications that should be on the computer
1.SAP Crystal Reports For SAP Bussines One 14.2.8.3426
2.SAP Crystal Reports runtime engine for .NET Framework (64-bit) 13.0.31.4010 || 13.0.31.3810
3.SAP Crystal Reports, version for Microsoft Visual Studio 13.0.31.4010 || 13.0.31.3810
All problems will be solved after downloading this apps...
Solution 18:[18]
This is an old question but I found it searching for an answer. It mattered the order of installation. I uninstalled the CR Runtime and uninstalled my Windows Forms App. Installed Windows Forms App first, then reinstalled CR Runtime. Problem gone. Your results may differ.
Solution 19:[19]
I faced the same issue. The target platform was Any CPU in my case. But the checkbox "Prefer-32Bit" was checked.. Unchecking the same resolved the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow

