none
PrintDlgEx? External component has thrown an exception RRS feed

  • Question

  • Hi all!

    ReportViewer opens and displays the formatted localreport, but when I press the "Print" button preview disappears and shows "External component has thrown an exception", instead of showing the "select printer dialog". After that I get a message box that shows me the following exception:

    System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
    at System.Windows.FormsUnsafeNativeMethds.ThemingScope.DeactivateActCtx(Int32 dwFlags, IntPtr lpCookie)
    ...

    Tested with VS2010 on Win7 Pro x64, and client machine (Win7 Pro x86) with Framework 4.0 and ReportViewer 2010 Redist. I also tried different combinations for page borders or landscape mode. Pressing the refresh button in the menubar restores the preview, but print button fails next time anyway. On the client machine I also have other printers installed, but both fail. On another test machine (WinXP Pro x86) everything works. All logged on users are administrators.

    Edit: Meanwhile I found out ReportViewer raises the ReportError event (previously RenderingComplete with no error and no warnings), which shows same exception but different stack trace:

    at System.Windows.Forms.UnsafeNativeMethods.PrintDlgEx(PRINTDLGEX lppdex)
    at System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, PRINTDLGEX data)
    ...

    I also tried deleting and re-creating the report, but it doesn't work either. All other reports (partially including the same sub-reports) work on Win7 and WinXP!

    How can I fix this problem on Win7 machines?

    greets

    Thursday, January 27, 2011 11:34 AM

All replies

  • I just solved the same issue.  I hope this helps others.  

    In creating a test program from scratch, everything worked perfectly.  The difference was in my program, I did not have the [STAThread] attribute specified.  Check the default winform project from VS2010:

     

        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    

    If you remove the [STAThread], you will get the above error when pressing the print button on a ReportViewer.

    • Edited by Rook1969 Tuesday, November 29, 2011 8:47 PM
    Tuesday, November 29, 2011 8:14 PM