“CrystalDecisions.Shared.SharedUtils"的类型初始值设定项引发异常 [英] The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception

查看:63
本文介绍了“CrystalDecisions.Shared.SharedUtils"的类型初始值设定项引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,但遇到了一个问题.当我运行我的代码时,我收到此错误消息:

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

消息标题是TypeInitializerException was unhandled".

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

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

I receive this error at this line of code:

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

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

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:

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

这条消息的标题是InvalidOperationException was unhandled".错误就在这一行:

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

db.Open();

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

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

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

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?

堆栈跟踪:

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:UsersWillDesktopClient_ManagerSyndicateIIReportViewer.Designer.cs:line 31
       at Client_Manager.ReportViewer..ctor() in C:UsersWillDesktopClient_ManagerSyndicateIIReportViewer.cs:line 27
       at Client_Manager.Form1..ctor() in C:UsersWillDesktopClient_ManagerSyndicateIIForm1.cs:line 174
       at Client_Manager.Program.Main() in C:UsersWillDesktopClient_ManagerSyndicateIIProgram.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-PCWill
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:UsersWillDesktopClient_ManagerSyndicateIIinDebugClient_Manager.vshost.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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: 

推荐答案

这看起来是原来的问题:

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.

所以看起来要么如果log4net有不同架构的多个版本,则您使用的是错误的log4net版本,或者您只是错误地复制了程序集.日志的这一部分似乎也很相关:

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

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.

这篇关于“CrystalDecisions.Shared.SharedUtils"的类型初始值设定项引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆