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...
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?
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.
When a static constructor throws an exception, it is wrapped inside a TypeInitializationException. You need to check the exception object's InnerException property to see the actual exception.
In a staging / production environment (where you don't have Visual Studio installed), you'll need to either:
- Trace/Log the exception and its InnerException (recursively): Add an event handler to the
AppDomain.UnhandledExceptionevent, and put your logging/tracing code there. UseSystem.Diagnostics.Debug.WriteLinefor tracing, or a logger (log4net, ETW). DbgView (a Sysinternals tool) can be used to view the Debug.WriteLine trace. - Use a production debugger (such as WinDbg or NTSD) to diagnose the exception.
- Use Visual Studio's Remote Debugging to diagnose the exception (enabling you to debug the code on the target computer from your own development computer).
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.
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
if you are using visual studio , enable the build property "Prefer 32-bit". see image below.
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
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.
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!
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.
Project Properties -> Compile -> Target CPU -> Any CPU And uncheck Prefer 32 bit
Done
-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...
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.
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.
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.
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.
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. :)
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.
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.
I had the same problem and I solved it installing both crystal Report Runtime 32 and 64 bit both version
I had the same issue because I had updated my visual studio from 2017 to 2019. I had updated crystal report for VS19 too but problem remained the same. After facing so much trouble I have taken two action
1) Changed the target framework of my project to .NET Framework 4.6.1
2) I checked the CrystalReport dlls in reference folder of my project I found it was still showing old version. So I deleted all CrystalReport dlls and added again in my project.
Everything became fine. Cheers
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.