Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 884
gwin003 Avatar asked May 20 '13 20:05

gwin003


3 Answers

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.

like image 141
Jeremy Holovacs Avatar answered Oct 14 '22 05:10

Jeremy Holovacs


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:

  1. Trace/Log the exception and its InnerException (recursively): Add an event handler to the AppDomain.UnhandledException event, and put your logging/tracing code there. Use System.Diagnostics.Debug.WriteLine for tracing, or a logger (log4net, ETW). DbgView (a Sysinternals tool) can be used to view the Debug.WriteLine trace.
  2. Use a production debugger (such as WinDbg or NTSD) to diagnose the exception.
  3. 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).
like image 31
M.A. Hanin Avatar answered Oct 14 '22 07:10

M.A. Hanin


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.

like image 10
shahk26 Avatar answered Oct 14 '22 05:10

shahk26