我正在做一个项目并且遇到了问题。当我运行我的代码时,我收到此错误消息:
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 was unhandled”。错误就在这一行:
db.Open();
db,当然,被设置为一个新的 OleDbConnection(connection)。连接 = 一个访问数据库。
为什么当平台目标是 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: