The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception
Asked Answered
U

21

43

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?

Ultramontanism answered 20/5, 2013 at 20:57 Comment(0)
F
17

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).
Fortaleza answered 20/5, 2013 at 23:13 Comment(2)
Thanks, this put me on the right path. I have implemented my own exception logging, but I wasnt logging the InnerExceptions correctly.Ultramontanism
Hey! man, 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 as mentioned.Cochrane
P
25

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.

Prolusion answered 10/6, 2013 at 15:18 Comment(2)
My solution involved me not using the correct log4net assembly that Crystal wanted. I was using log4net in my application to log my own exceptions, but Crystal wanted a version of log4net that had a different PublicKeyToken. Once I included the correct version in my installer, it worked.Ultramontanism
I've seen SAP documentation that explicitly specifies to set it to 32 or 64 bit NOT AnyCpu.Sulph
F
17

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).
Fortaleza answered 20/5, 2013 at 23:13 Comment(2)
Thanks, this put me on the right path. I have implemented my own exception logging, but I wasnt logging the InnerExceptions correctly.Ultramontanism
Hey! man, 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 as mentioned.Cochrane
C
11

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.

Carlitacarlo answered 23/7, 2015 at 18:42 Comment(0)
A
9

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
Allpurpose answered 5/6, 2014 at 18:59 Comment(1)
Are you saying an app of that name should be installed? Having a hard time parsing what you wrote. If you could clear it up, that would be great.Orchid
S
7

if you are using visual studio , enable the build property "Prefer 32-bit". see image below.

enter image description here

Spout answered 24/4, 2018 at 8:19 Comment(1)
I know this is an old post but for me, it was the contrary, the runtime was x64 on the production server and I had the "Prefer 32-bit" checked on the platform target option on my VS2015 solution. I had to uncheck it and it worked ! Thanks anyway for the proposition, it saved me from more days or hair removing :).Fabrikoid
I
6

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

Isolda answered 25/4, 2016 at 5:23 Comment(0)
U
3

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:

  1. I set x86 for my application, then I set x64 for my setup application

  2. 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

  3. 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.

Unnatural answered 7/2, 2016 at 13:34 Comment(0)
W
2

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!

Wincer answered 22/10, 2013 at 15:17 Comment(1)
Unit Test not unrecognized C:\Users\YourUserName\AppData\Local\Microsoft.TestHost.x86\TestSourceHost__Enumering_StrongName_m5l5weancdfp4s54niytdpqgfzeu55uc\15.5.1\user.config Acanthus
F
1

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.

Finicking answered 28/8, 2013 at 9:25 Comment(0)
A
1

Project Properties -> Compile -> Target CPU -> Any CPU And uncheck Prefer 32 bit

Done

Asturias answered 30/11, 2020 at 9:51 Comment(0)
L
1

-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...

Lyon answered 21/12, 2021 at 9:19 Comment(0)
H
1

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.

Helicopter answered 14/4, 2022 at 13:31 Comment(0)
N
0

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.

Nonaligned answered 3/2, 2015 at 7:57 Comment(0)
L
0

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.

Landowska answered 9/6, 2015 at 8:4 Comment(0)
S
0
  1. 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

  2. Download c++ redist 2005 or 2008(which is your tool)

  3. Install both and restart your system

  4. Problem solved.

Sweetandsour answered 22/7, 2016 at 14:1 Comment(0)
C
0

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. :)

Cochrane answered 18/10, 2016 at 13:26 Comment(0)
S
0

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.

Sivas answered 9/3, 2017 at 13:7 Comment(0)
H
0

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.

Heterotaxis answered 29/1, 2018 at 23:45 Comment(0)
C
0

I had the same problem and I solved it installing both crystal Report Runtime 32 and 64 bit both version

Churchly answered 28/10, 2020 at 21:20 Comment(0)
J
0

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

Jointed answered 17/7, 2023 at 10:8 Comment(0)
H
-1

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.

Headphone answered 6/1, 2016 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.