gpt4 book ai didi

c# - 'CrystalDecisions.Shared.SharedUtils' 的类型初始值设定项抛出异常

转载 作者:太空狗 更新时间:2023-10-30 00:01:43 27 4
gpt4 key购买 nike

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

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

消息的标题是“TypeInitializerException was unhandled”。

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

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

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

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

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

db.Open();

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

为什么当平台目标是 x86 时我收到第一个错误而不是第二个错误,如果平台目标是 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:\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:

最佳答案

这看起来像是原始问题:

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 版本,如果它针对不同的体系结构有多个版本,或者您只是错误地复制了程序集。日志的这一部分似乎也相关:

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.

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

关于c# - 'CrystalDecisions.Shared.SharedUtils' 的类型初始值设定项抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12374681/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com