C# “CrystalDecisions.Shared.SharedUtils”的类型初始值设定项引发异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12374681/
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-09 23:03:03  来源:igfitidea点击:

The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception

c#visual-studio-2010crystal-reports-xiunhandled-exception

提问by woods

I'm working on a project and have run into an issue. When I run my code I get this error message:

我正在做一个项目并且遇到了一个问题。当我运行我的代码时,我收到此错误消息:

The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception

The title of the message is "TypeInitializerException was unhandled".

消息的标题是“TypeInitializerException 未处理”。

I receive this error at this line of code:

我在这行代码中收到此错误:

this.crystalReportViewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();

I've been looking up ways to fix this issue, but I keep running into another issue. Everything I find about how to fix this says that the platform target should be changed to x86. All the comments that follow that advice are always positive because it seems to work for everyone, but it's not working for me. I also tried the platform target as x64. When I do that, I don't receive the previously stated error, but instead I receive a new error that reads:

我一直在寻找解决此问题的方法,但我一直遇到另一个问题。我找到的有关如何解决此问题的所有信息都表明平台目标应更改为 x86。遵循该建议的所有评论总是积极的,因为它似乎对每个人都有效,但对我却不起作用。我还尝试将平台目标设为 x64。当我这样做时,我没有收到前面提到的错误,而是收到一个新的错误,内容如下:

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

The title of thismessage is "InvalidOperationException was unhandled". And the error is on this line:

消息的标题是“未处理 InvalidOperationException”。错误在这一行:

db.Open();

db, of course, being set to a new OleDbConnection(connection). connection = an Access db.

db,当然,被设置为一个新的 OleDbConnection(connection)。连接 = 一个 Access 数据库。

Why am I receiving the first error and not the second error when platform target is x86, and vice versa if the platform target is x64?

当平台目标是 x86 时,为什么我收到第一个错误而不是第二个错误,如果平台目标是 x64,反之亦然?

Stacktrace:

堆栈跟踪:

System.TypeInitializationException was unhandled
  Message=The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception.
  Source=CrystalDecisions.Shared
  TypeName=CrystalDecisions.Shared.SharedUtils
  StackTrace:
       at CrystalDecisions.Shared.SharedUtils.get_CurrentControl()
       at CrystalDecisions.Shared.SharedUtils.GetEffectiveCulture()
       at CrystalDecisions.Shared.LocaleManager..ctor()
       at CrystalDecisions.Windows.Forms.CrystalReportViewer.InitReportViewer()
       at CrystalDecisions.Windows.Forms.CrystalReportViewer..ctor()
       at Client_Manager.ReportViewer.InitializeComponent() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.Designer.cs:line 31
       at Client_Manager.ReportViewer..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.cs:line 27
       at Client_Manager.Form1..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Form1.cs:line 174
       at Client_Manager.Program.Main() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.BadImageFormatException
       Message=Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. An attempt was made to load a program with an incorrect format.
       Source=CrystalDecisions.Shared
       FileName=log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
       FusionLog==== Pre-bind state information ===
LOG: User = Will-PC\Will
LOG: DisplayName = log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Will\Desktop\Client_Manager\SyndicateII\bin\Debug\Client_Manager.vshost.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
LOG: Attempting download of new URL file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/log4net.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

       StackTrace:
            at CrystalDecisions.Shared.SharedUtils..cctor()
       InnerException: 

回答by Jon Skeet

This looks like it's the original problem:

这看起来是原来的问题:

InnerException: System.BadImageFormatException
   Message=Could not load file or assembly 'log4net, Version=1.2.10.0,
        Culture=neutral, PublicKeyToken=692fbea5521e1304'
   or one of its dependencies. An attempt was made to load a program
   with an incorrect format.

So it looks like eitheryou're using the wrong version of log4net if it has multiple versions for different architectures, oryou've just copied the assembly incorrectly. This part of the log seems relevant too:

因此,看起来要么你正在使用log4net的版本错误,如果它有多个版本不同的架构,或者你刚刚复制的组件不正确。日志的这一部分似乎也很相关:

LOG: Attempting download of new URL
file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/log4net.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

That looks like it's the file you need to check for correctness.

看起来这是您需要检查正确性的文件。

回答by fgpx78

It could be useful to someone: if you have the option to do it, go to IIS and set the Application Pool to 32 bit applications only.

它可能对某人有用:如果您可以选择这样做,请转到 IIS 并将应用程序池设置为仅 32 位应用程序。

That made the trick for me.

这对我来说是个窍门。

(Of course, your application could be made to run only on 64 bit. In that case, I think the installing of the 64 bit redistributable of CrystalReports should solve the issue)

(当然,您的应用程序可以只在 64 位上运行。在这种情况下,我认为安装 CrystalReports 的 64 位可再发行组件应该可以解决问题)

回答by Jay-r

You should install SAP Crystal Reports runtime for .Net 4.0

您应该为 .Net 4.0安装SAP Crystal Reports 运行时

回答by Hien Nguyen

What I did for this error was to install CrystalReport Runtime. It seems missing some dlls. Check this post out for the package SAP Crystal Reports runtime for .Net 4.0 (64-bit).

我为这个错误所做的是安装 CrystalReport Runtime。似乎缺少一些dll。查看这篇文章,了解适用于 .Net 4.0 (64-bit) 的 SAP Crystal Reports 运行时包。

回答by Andy Stannard

Make sure you have the correct version installed for your environment it try the 64bit installer not the 32bit one as they will both install fine but then the wrong one will cause the mentioned error.

确保您为您的环境安装了正确的版本,它尝试使用 64 位安装程序而不是 32 位安装程序,因为它们都可以正常安装,但错误的安装程序将导致上述错误。

I had the exact same problem and installing the 64bit version instead fixed things for me

我遇到了完全相同的问题并安装了 64 位版本而不是为我修复了一些问题

回答by Hayden Wiltshire

I had the same issue. 32bit app running on a 64bit server. I had installed the 64bit runtime and the above exception was thrown. After installing the 32bit version all worked as expected.

我遇到过同样的问题。在 64 位服务器上运行的 32 位应用程序。我已经安装了 64 位运行时并抛出了上述异常。安装 32 位版本后,一切都按预期工作。

回答by user5739566

this problem is the driver of crystal report is not install on the client and they are in the crystal report home directory and sub folder and named crystal.forms and crystal.shared and crystal suport and so

这个问题是客户端没有安装Crystal Report的驱动,它们在Crystal Report主目录和子文件夹中,名为crystal.forms和crystal.shared,以及Crystal suport等

回答by Alessandro Bernardi

I solvedmy problem changing the application pool identity, using the local profile and the administrator login (take a look if the password expires).

我解决了更改应用程序池标识的问题,使用本地配置文件和管理员登录(看看密码是否过期)。

Symptoms are similar. I think that Log4netpops up because Crystal wants to log the error that has already happened. I don't have any log4net in my project, neither the dll file.

症状相似。我认为Log4net弹出是因为 Crystal 想要记录已经发生的错误。我的项目中没有任何 log4net,也没有 dll 文件。

My project is compiled with AnyCpu over a 64bit server, and I already have both CRRedist x86 x64 installed.

我的项目是在 64 位服务器上使用 AnyCpu 编译的,并且我已经安装了两个 CRRedist x86 x64。

I also tried to run in 32bit mode without any change.

我还尝试在 32 位模式下运行而不做任何更改。

回答by Gurpreet

I'm having the same issue with crystal report, I just change Platform Target "Any CPU" as you can see in screenshot below too. enter image description here

我在水晶报告中遇到了同样的问题,我只是更改了平台目标“任何 CPU”,如下面的屏幕截图所示。 在此处输入图片说明

回答by Xtremexploit

Depending on the version you have installed, if you only have the 32-bit version installed you must compile to x86 or if you only have the 64-bit version installed you must compile on x64, if you have both versions installed you must compile on anycpu.

根据你安装的版本,如果你只安装了 32 位版本你必须编译到 x86 或者如果你只安装了 64 位版本你必须在 x64 上编译,如果你安装了两个版本你必须编译任何CPU。

If you compile on anycpu but on the pc you have the 32-bit version it will send you an error.

如果您在 anycpu 上编译但在 pc 上您拥有 32 位版本,它将向您发送错误。

Cheers

干杯