C# “CrystalDecisions.CrystalReports.Engine.ReportDocument”的类型初始值设定项引发异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16658300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:35:38  来源:igfitidea点击:

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

c#.netdeploymentinstallshieldcrystal-reports-2010

提问by gwin003

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:

我正在向我的客户端部署一个桌面应用程序,该应用程序使用 Crystal Reports API 来显示和打印表单。我正在使用 InstallShield 2012 构建我的安装程序。我还包含了 .NET 4.0 Framework 以及所有 Crystal 程序集。我有两个(有点相关的)问题:

1) Whenever I tried to run the application on the client machine, I get the following error:

1) 每当我尝试在客户端计算机上运行应用程序时,都会出现以下错误:

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

I have no idea what I am forgetting here. The CrystalDecisions.CrystalReports.Enginedll is being registered in the GAC correctly, as are about 10 other Crystal assemblies.

我不知道我在这里忘记了什么。所述CrystalDecisions.CrystalReports.EngineDLL在GAC被注册正确,因为是大约等10个晶体组件。

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?

2)我在 SAP 论坛上问过这个问题,有人告诉我需要将 .NET 2.0 Framework 与 .NET 4.0 Framework 一起包含在内。我尝试在我的安装程序包中包含 .NET 2.0 可再发行组件,但安装程序没有安装它。安装程序是否看到我安装了 4.0,因此跳过 2.0 安装?

采纳答案by M.A. Hanin

When a static constructor throws an exception, it is wrapped inside a TypeInitializationException. You need to check the exception object's InnerExceptionproperty to see the actual exception.

当静态构造函数抛出异常时,它被包装在一个TypeInitializationException. 您需要检查异常对象的InnerException属性以查看实际异常。

In a staging / production environment (where you don't have Visual Studio installed), you'll need to either:

在暂存/生产环境(未安装 Visual Studio)中,您需要:

  1. Trace/Log the exception and its InnerException (recursively): Add an event handler to the AppDomain.UnhandledExceptionevent, and put your logging/tracing code there. Use System.Diagnostics.Debug.WriteLinefor 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).
  1. 跟踪/记录异常及其 InnerException(递归):向事件添加一个事件处理程序AppDomain.UnhandledException,并将您的记录/跟踪代码放在那里。使用System.Diagnostics.Debug.WriteLine追踪,或记录(log4net的,ETW)。DbgView(Sysinternals 工具)可用于查看 Debug.WriteLine 跟踪。
  2. 使用生产调试器(例如 WinDbg 或 NTSD)来诊断异常。
  3. 使用 Visual Studio 的远程调试诊断异常(使您能够从您自己的开发计算机调试目标计算机上的代码)。

回答by Jeremy Holovacs

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 verytouchy about 32/64 bit assemblies, and makes some pretty counterintuitive assumptions which are very difficult to troubleshoot.

如果您在 64 位计算机上安装,请确保“构建”选项卡下的应用程序属性将“任何 CPU”作为平台目标,如果有选项,请取消选中“首选 32 位”复选框。Crystal对 32/64 位程序集非常敏感,并做出了一些非常违反直觉的假设,这些假设很难排除故障。

回答by Rob King

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.

我在 32 位机器上没有收到错误,但在 64 位机器上,所以我将目标平台从 x86 更改为 Any CPU,它解决了问题。

回答by Hossein POURAKBAR

As "M.A. Hanin" said above, it can caused by an InnerExceptionlike this:

正如上面“MA Hanin”所说,它可能是由InnerException这样的:

"Unrecognized configuration section userSettings. (C:\Users\Pourakbar.h\AppData\Local\Accounting\Accounting.vshost.exe_Url_a4h1gnabohiu4wgiejk0d21rc2kbwr4g.0.0.0\user.config line 3)"

and I deleted the folder: C:\Users\Pourakbar.h\AppData\Local\Accounting\Accounting.vshost.exe_Url_a4h1gnabohiu4wgiejk0d21rc2kbwr4gfrom my computer and that worked for me!

我删除了文件夹:C:\Users\Pourakbar.h\AppData\Local\Accounting\Accounting.vshost.exe_Url_a4h1gnabohiu4wgiejk0d21rc2kbwr4g从我的电脑上,这对我有用!

回答by tyrodeveloper

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

回答by Faheem

The type initializer for CrystalDecisions.CrystalReports.Engine.ReportDocumentthrew an exception.

The type initializer for CrystalDecisions.CrystalReports.Engine.ReportDocument抛出异常

I changed the target platform from x86to Any CPUand it resolved the issue.

我将目标平台从 更改x86Any CPU并解决了问题。

回答by Antonio Cabilos

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.

我忘了有一个像
“connectionStrings”“/connectionStrings”这样的连接元素,也许这取决于你在代码中做了什么。我的错误是由于这个连接元素我无法打开一个类。

回答by shahk26

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.

我收到了类似的消息,经过多次在线搜索并提出所有建议,没有任何帮助。最后我找到了解决方案。在我的 IIS 服务器中,在应用程序池提前选项下,有一个“启用 32 位应用程序”选项 - 从 false 更改为 true,重新启动 IIS 服务器后,我的程序开始生成 pdf 文件。

回答by Nitika Ish Goel

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.

我遇到了同样的问题。在我的例子中,目标平台是 Any CPU。但是选中了“Prefer-32Bit”复选框。取消选中同样解决了问题。

回答by Pranesh Janarthanan

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

我在网上搜索了一整天,我自己找到了一个解决方案。同样的情况,该应用程序在开发人员机器上运行良好,但在部署时抛出异常“crystaldecisions.crystalreports.engine.reportdocument 抛出异常”详细信息:缺少 sys.io.filenotfoundexcep crystaldecisions.reportappserver.commlayer 版本 13.0.2000

My IDE: MS VS 2010 Ultimate, CR V13.0.10

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

  1. 我为我的应用程序设置了 x86,然后我为我的安装应用程序设置了 x64

  2. 先决条件:我将支持的 CR 运行时文件 CRRuntime_32bit_13_0_10.msi、CRRuntime_64bit_13_0_10.msi 放在以下目录 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\Crystal Framework Reports for .0。

  3. 将合并模块文件包含到安装项目中。这里的版本不是很严重,因为我使用 13.0.10 soft, 13.0.16 合并模块文件我包含的文件:CRRuntime_13_0_16.msm 这个文件是在设置的 msm 文件中找到的一个。

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

dll 文件版本不会导致任何问题。

In your developer machine you confirm it same.

在您的开发机器中,您确认它相同。

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

我需要声望点,如果这个答案有用,请将其标记为有用(+1)