locked
System.TypeInitializationException was unhandled

    Question

  • I have recently put Crystal Reports XI Release 2 onto my PC, after having installed CR XI SP 2.  I had an older Visual Studio .NET 2003 WinForms app, written in C#, that I decided to convert to VS .NET  2005.  I went through that process and VS.NET 2005 noticed the newer Crystal Reports and so it updated everything.  I changed absolutely nothing in the code, just did the update.  Then when I go to run it I get an error which is the following:

     


    System.TypeInitializationException was unhandled
      Message="The type initializer for 'CrystalDecisions.ReportSource.ReportSourceFactory' threw an exception."
      Source="CrystalDecisions.Windows.Forms"
      TypeName="CrystalDecisions.ReportSource.ReportSourceFactory"
      StackTrace:
           at CrystalDecisions.Windows.Forms.CrystalReportViewer..ctor()
           at AllClientsForISR.Form1.InitializeComponent() in D:\AllClientsForISR\Form1.cs:line 72
           at AllClientsForISR.Form1..ctor() in D:\AllClientsForISR\Form1.cs:line 39
           at AllClientsForISR.Form1.Main() in D:\AllClientsForISR\Form1.cs:line 157
           at System.AppDomain.nExecuteAssembly(Assembly 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)
           at System.Threading.ThreadHelper.ThreadStart()

     


    The line where this occurs is in the Windows Form Designer generated code region, so it is something I did not put there (in fact, it has been there since it was a VS .NET 2003 project).  I have removed the CrystalReportsViewer control, and put it back on again, and that didn't help.  I have checked the CrystalDecisions.* references that are a part of this project, to make certain that they are all the same version (11.5.3300.0) and that does not help.

    What is wrong and how do I fix it?

    Thursday, September 07, 2006 9:04 PM

All replies

  • I'm experiencing a similiar problem with CR10 and VS2005.  No upgrade, this is a fresh VS2005 project but I'm getting the same error in the InitializeComponent() method on the following line of code:

      Me.crystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer

    Rod, have you had any luck tracking down a solution for your problem?

    In addtion, my test form works fine and shows the report correctly in design mode but throws this error at runtime.

     

    System.TypeInitializationException was unhandled by user code
      Message="The type initializer for 'CrystalDecisions.ReportSource.ReportSourceFactory' threw an exception."
      Source="CrystalDecisions.Windows.Forms"
      TypeName="CrystalDecisions.ReportSource.ReportSourceFactory"
      StackTrace:
           at CrystalDecisions.Windows.Forms.CrystalReportViewer..ctor()
           at Rei.Repss.Form1.InitializeComponent() in C:\Documents and Settings\sstudy.REI\My Documents\Visual Studio\Projects\winRepss2\clsRepss\Reporting\Testing\Form1.vb:line 34
           at Rei.Repss.Form1..ctor() in C:\Documents and Settings\sstudy.REI\My Documents\Visual Studio\Projects\winRepss2\clsRepss\Reporting\Testing\Form1.vb:line 11
           at Rei.Repss.WinClient.frmRepssMain.RunReportTest() in C:\Documents and Settings\sstudy.REI\My Documents\Visual Studio\Projects\winRepss2\winRepss2\frmRepssMain.vb:line 47
           at Rei.Repss.WinClient.frmRepssMain.mnuFile_ReportTest_Click(Object sender, SmartItemClickEventArgs e) in C:\Documents and Settings\sstudy.REI\My Documents\Visual Studio\Projects\winRepss2\winRepss2\frmRepssMain.vb:line 259

    Monday, September 25, 2006 4:19 PM
  • Hello Stephen,

    No, I am sorry to say that I have not yet solved this problem.

    I checked bringing up the form with the CrystalReportsViewer on it (I hadn't done that before), and it came up just fine, within the designer.  But once I try to run it, I get that TypeInitializationException error.

    Monday, September 25, 2006 9:01 PM
  • Try to copy your source to a different folder. Regards Joe
    Tuesday, October 10, 2006 9:46 AM
  •  Error is coming as dlls required to run Crystal report are not registered in the m/c. Because of this reason only, Busiobj recommends to create websetup for crystal report deployment.

    Instead of going for this long process, i would recommend to create one windows application with one single form, in that drag one crystalreportviewer. Add one setup project in the same solution. In the setup, right click on its properties and add merge module files [ crystal11_net_embeddedreporting.msm and crystalreports11_maps.msm] and in the keycode of firstone add licence key.

    Run this msi file on the machine where the error is coming up. As this merge module will register the dlls which is required for your web app. [Or create full web setup program for your app]

    Thursday, March 15, 2007 4:39 PM
  •  

    I had the same problem. I tried it and it works. thanks!
    Friday, August 17, 2007 8:14 AM
  • Problem is that you don't have reference to the CrystalDecisions.ReportSource in your project. i suggest that you add one crystal report to the project in VS 2005 or add reference to the CrystalDecisions.ReportSource.dll. More Exception solutions regarding this exception and others. http://dileepsol.blogspot.com
    Friday, September 18, 2009 4:01 AM