Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

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

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

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:

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

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

db.Open();

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

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?

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: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: 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...