[c#] 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?

This question is related to c# .net deployment installshield crystal-reports-2010

The answer is


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.


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 had the same problem and I solved it installing both crystal Report Runtime 32 and 64 bit both version


  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.


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


For one full day i searched online and i found a solution on my own. 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.

I need reputation points, if this answer is useful kindly mark it useful(+1)


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


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

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.


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

enter image description here


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.


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


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.


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


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.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to deployment

error: This is probably not a problem with npm. There is likely additional logging output above Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature) repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter "Untrusted App Developer" message when installing enterprise iOS Application How do I copy directories recursively with gulp? How to deploy correctly when using Composer's develop / production switch? Enterprise app deployment doesn't work on iOS 7.1 Can not deserialize instance of java.lang.String out of START_OBJECT token Run command on the Ansible host Error when deploying an artifact in Nexus

Examples related to installshield

The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception MS Access DB Engine (32-bit) with Office 64-bit Programmatically extract contents of InstallShield setup.exe Extract MSI from EXE

Examples related to crystal-reports-2010

Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception