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

不想你离开。 提交于 2019-11-27 07:08:05

问题


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:\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: 

回答1:


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.




回答2:


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.

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)




回答3:


You should install SAP Crystal Reports runtime for .Net 4.0




回答4:


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.




回答5:


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




回答6:


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.

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




回答7:


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




回答8:


I solved my 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 Log4net pops 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.

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

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




回答9:


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



来源:https://stackoverflow.com/questions/12374681/the-type-initializer-for-crystaldecisions-shared-sharedutils-threw-an-exceptio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!