cancel
Showing results for 
Search instead for 
Did you mean: 

The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception.

Former Member
0 Kudos

I am creating a Visual BASIC .Net windows application in Visual Studio 2013.

I have set up a Crystal Report to use the dataset in SAP Crystal Reports 2011.

The Visual Basic .Net application is not using the Crystal Report Viewer.  It is using the Report Document class to export the report to a PDF and/or Excel file.  SAP Crystal Reports for Visual Studio has been installed.

The error message "The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception." occurs when running the application on a separate Windows 7 system.

I used InstallShield Express to create the setup package for the Visual BASIC .Net Windows application.

I have ran the setup package on a separate Windows 7 system.

The Windows application runs to the point that it shows the window for the application.  As soon as I click on the Run Report button, the error occurs.

Here is the code for the button:

        strProcedure = "btnRunReport_Click"

        Try

            Dim reportDocument1 As ReportDocument

            reportDocument1 = New ReportDocument()

            'reportDocument1.FileName = strCurPath + "\PlexACCPriceReport_2.rpt"

            If IsNothing(reportDocument1) Then

                MsgBox("reportDocument1 is Nothing.")

            End If

            MsgBox("From Date is " & dtpFromDate.Text & vbCrLf & "To Date is " & dtpToDate.Text)

            'reportDocument1 = Nothing

        Catch ex As Exception

            strErrorMsg = "Date/Time: " & Format(Now, "MM/dd/yyyy HH:mm:ss") & vbCrLf & _

                        "Procedure: " & strProcedure & vbCrLf & _

                        "Error Message: " & ex.Message & vbCrLf & vbCrLf

            MsgBox(strErrorMsg, MsgBoxStyle.Critical)

        End Try

The error occurs on the following line of code:

            reportDocument1 = New ReportDocument()

What do I need to do to resolve this problem?

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Hi Keith

What is the full error message and what msm file(s) were included in your InstallShield setup project?

Oh, and see this KBA


- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Message was edited by: Ludek Uher

Former Member
0 Kudos

Ludek,

        What do you mean by msm files included in InstallShield project?

        The application files included in the InstallShield project are the windows application .exe file and the Crystal Report .rpt file.

        By the way, the project for the windows application is set to Any CPU and has Prefer 32-bit checked in the Project settings in Compile tab.

        I have tried unchecking Prefer 32-bit and got another error as well as the exception.

Here is a list of files that were installed:

Volume in drive C is OS

Volume Serial Number is 1251-1E7D

Directory of C:\VBApps\TestVBApp1

07/22/2014  02:15 PM    <DIR>          .

07/22/2014  02:15 PM    <DIR>          ..

06/24/2014  06:47 PM           372,736 CrystalDecisions.CrystalReports.Engine.dll

06/24/2014  06:50 PM            65,536 CrystalDecisions.ReportAppServer.ClientDoc.dll

06/24/2014  06:50 PM            49,152 CrystalDecisions.ReportAppServer.CommLayer.dll

06/24/2014  06:50 PM           135,168 CrystalDecisions.ReportAppServer.CommonControls.dll

06/24/2014  06:50 PM            36,864 CrystalDecisions.ReportAppServer.CommonObjectModel.dll

06/24/2014  06:50 PM           176,128 CrystalDecisions.ReportAppServer.Controllers.dll

06/24/2014  06:50 PM            36,864 CrystalDecisions.ReportAppServer.CubeDefModel.dll

06/24/2014  06:50 PM           258,048 CrystalDecisions.ReportAppServer.DataDefModel.dll

06/24/2014  06:47 PM            57,344 CrystalDecisions.ReportAppServer.DataSetConversion.dll

06/24/2014  06:50 PM             5,120 CrystalDecisions.ReportAppServer.ObjectFactory.dll

06/24/2014  06:50 PM           155,648 CrystalDecisions.ReportAppServer.Prompting.dll

06/24/2014  06:50 PM           368,640 CrystalDecisions.ReportAppServer.ReportDefModel.dll

06/24/2014  06:50 PM            15,872 CrystalDecisions.ReportAppServer.XmlSerialize.dll

06/24/2014  06:47 PM           876,544 CrystalDecisions.Shared.dll

06/24/2014  06:50 PM           237,568 log4net.dll

07/14/2014  02:10 PM            56,320 PlexACCPriceReport_2.rpt

07/22/2014  05:00 PM            32,768 TestVBApp1.exe

----------------------------------------------------------------------------------------------------------------------------

       

Here is the full error message:

See the end of this message for details on invoking

just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************

System.TypeInitializationException: The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. An attempt was made to load a program with an incorrect format.

   at CrystalDecisions.CrystalReports.Engine.ReportDocument..cctor()

   --- End of inner exception stack trace ---

   at CrystalDecisions.CrystalReports.Engine.ReportDocument..ctor()

   at TestVBApp1.Form1.btnRunReport_Click(Object sender, EventArgs e)

   at System.Windows.Forms.Control.OnClick(EventArgs e)

   at System.Windows.Forms.Button.OnClick(EventArgs e)

   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

   at System.Windows.Forms.Control.WndProc(Message& m)

   at System.Windows.Forms.ButtonBase.WndProc(Message& m)

   at System.Windows.Forms.Button.WndProc(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************

mscorlib

    Assembly Version: 4.0.0.0

    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR

    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll

----------------------------------------

TestVBApp1

    Assembly Version: 1.0.0.0

    Win32 Version: 1.0.0.0

    CodeBase: file:///C:/VBApps/TestVBApp1/TestVBApp1.exe

----------------------------------------

Microsoft.VisualBasic

    Assembly Version: 10.0.0.0

    Win32 Version: 11.0.50938.18408 built by: FX451RTMGREL

    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll

----------------------------------------

System

    Assembly Version: 4.0.0.0

    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL

    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll

----------------------------------------

System.Core

    Assembly Version: 4.0.0.0

    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL

    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll

----------------------------------------

System.Windows.Forms

    Assembly Version: 4.0.0.0

    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL

    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

----------------------------------------

System.Drawing

    Assembly Version: 4.0.0.0

    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL

    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

----------------------------------------

System.Runtime.Remoting

    Assembly Version: 4.0.0.0

    Win32 Version: 4.0.30319.34108 built by: FX45W81RTMGDR

    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll

----------------------------------------

CrystalDecisions.CrystalReports.Engine

    Assembly Version: 13.0.2000.0

    Win32 Version: 13.0.9.1312

    CodeBase: file:///C:/VBApps/TestVBApp1/CrystalDecisions.CrystalReports.Engine.DLL

----------------------------------------

CrystalDecisions.Shared

    Assembly Version: 13.0.2000.0

    Win32 Version: 13.0.9.1312

    CodeBase: file:///C:/VBApps/TestVBApp1/CrystalDecisions.Shared.DLL

----------------------------------------

************** JIT Debugging **************

To enable just-in-time (JIT) debugging, the .config file for this

application or computer (machine.config) must have the

jitDebugging value set in the system.windows.forms section.

The application must also be compiled with debugging

enabled.

For example:

<configuration>

    <system.windows.forms jitDebugging="true" />

</configuration>

When JIT debugging is enabled, any unhandled exception

will be sent to the JIT debugger registered on the computer

rather than be handled by this dialog box.

--------------------------------------------------------------------------------

Please let me know if there is any additional information you need.  I look forward to your reply.

Keith Jackson

Former Member
0 Kudos

I still need help to resolve this problem.

Please help.

Sincerely,

Keith Jackson

former_member183750
Active Contributor
0 Kudos

Hi Keith

Please remember these are community forums, not support as such. E.g.; you may get an answer, you may not. It may be timely, it may not. If this is a critical issue, you do have the option of creating a phone support incident here:

Crystal Single Case Technical Support - SAP Business Objects US Online Store | SAP Online Store

Now, your response:

   What do you mean by msm files included in InstallShield project?

tells me that you are not deploying the CR runtime. E.g.; you must include the correct cr msm file in your InstallShield project.From the error, it is obvious that you are using version 13 of CR (SAP Crystal Reports, Developer Version for Visual Studio .NET), thus the msm files to use are noted in this document:

Be sure to use the correct "bitness" msm.

- Ludek

Former Member
0 Kudos

Ludek,

      Thanks for your help!

      I have decided to use the Crystal Reports Runtime 32-bit .msi instead.  With using that, it is now working.

Sincerely,

Keith Jackson

former_member183750
Active Contributor
0 Kudos

Perfect. Probably the better decision as the MSI includes the VS++ runtime dependencies. The MSM does not due to some licensing issues.

Happy coding,

- Ludek

Answers (0)