System.ApplicationException: The current printer caused a Windows error

Posted by: wvdbroek on 14 September 2017, 9:29 am EST

  • Posted 14 September 2017, 9:29 am EST

    [activereports_archive]Development Environment:



    - Windows 8 Professional



    - Visual Studio 2012 Professional (Using VB, .NET Framework 4)



    - ActiveReports 7.1.7572.0







    My customer runs the compiled application on Windows Server 2012.







    When using the Print button from the Viewer, after showing the Printer Properties window, this error might appear:







    System.ApplicationException: The current printer caused a Windows error:



    —> System.ArgumentException: Handle 0 is not valid.



    by System.Drawing.Printing.PrinterSettings.SetHdevmode(IntPtr hdevmode)



    by GrapeCity.ActiveReports.Viewer.Win.Controls.CustomPrintDialog.#tTB(#tqC pdlg)



    by GrapeCity.ActiveReports.Viewer.Win.Controls.CustomPrintDialog.RunDialog(IntPtr hwndOwner)



    by System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)



    by GrapeCity.ActiveReports.Viewer.Win.Printing.PrintImpl.#zs(#q0B documentPrintAdapter, Action

    1 action) <br />   by GrapeCity.ActiveReports.Viewer.Win.Printing.PrintImpl.Print(#q0B documentPrintAdapter, Boolean showPrintDialog, Boolean showPrintProgressDialog, Boolean usePrintingThread, Action
    1 action)



    by GrapeCity.Viewer.Common.ViewModel.ToolbarViewModel.<>c__DisplayClass39.#5kz()



    by System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)



    by System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)



    by System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)



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



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



    by System.Windows.Forms.ToolStrip.WndProc(Message& m)



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







    Very thorough testing learned:







    The error above appears when:



    - The end user is not printing to the default printer, or



    - The end user is printing to the default printer and has at least 1 property changed (color, duplex, …)







    It is not dependant on one specific printer. Various printers are defined and they are all affected.







    Problem in brief:



    The only way to print without getting this error, is printing to the default printer, without changing any printer properties.







    More information:



    I have very recently setup my development PC from scratch:



    Windows 7 - Windows 8



    VS2010 - VS2012



    AR6 - AR7







    When I read the exception, it seams the exception is thrown when ActiveReports’ CustomPrintDialog is passing its setting to System.Drawing.Printing.PrinterSettings.



    I am not able to reproduce this problem on my development PC. It seems related to running the application on Windows Server 2012.







    Additional information:



    It seems this error also has something to do with upgrading to ActiveReports 7.1.7572.0. When I used ActiveReports 7.1.7470.0, the end users also complained about printing.



    With ActiveReports 7.1.7470.0 they did not get an error. But when printing, they have to change printer setting very often: Setting color to yes/no, using simplex or duplex, and selecting a different paper bin.



    Whatever printer setting(s) they changed, is was completely ignored by ActiveReports. Since 7.1.7572.0 is used, they get this error instead.



    Therefore I think GrapeCity/ComponentOne must have been working on this part of ActiveReports.







    Urgent:



    I know, everybody wants his problem solved yesterday. In my case, about 15 employees are affected by this problem on a daily basis. My customer is not amused, to put it mildly. Please help…[/activereports_archive]

  • Posted 14 September 2017, 9:29 am EST

    [activereports_archive]



    Some additional info







    After downgrading from ActiveReports 7.1.7572.0 to 7.1.7470.0 the error was gone. But, as I mentioned before, changing printer settings is ignored.



    After clicking ‘Print’ in the viewer, the print setting dialog pops up. I select a printer that defaults to printing in black and white. I set the printer setting to printing in color. But it still prints in black and white.



    The same is true when selecting duplex printing. It keeps printing simplex.



    [/activereports_archive]

  • Posted 14 September 2017, 9:29 am EST

    [activereports_archive]Hello,







    I tried replicating the issue but was unable to so at my end. The exe of was creatd on a machine with following configuration :



    Win8 + 32Bit + VS2012



    ActiveReports 7.1.7572.0







    And the compiled application was run on a Win 2012 Server machine without any error. Even on changing the print settings, the same were reflected in the resultant printout.







    Could you please share your sample application with us. This would help us in narrowing down the issue and providing you with appropriate solution.







    Regards,



    Mohita



    [/activereports_archive]

  • Posted 14 September 2017, 9:29 am EST

    [activereports_archive]Hi Mohita,







    This problem almost drove me crazy. I was not able to reproduce this problem in a simple sample.







    I still do not know what the exact problem was. It might have been related to a certain Xerox printer. Since my customer wanted me to solve the problem I tried a different approach.



    In my earlier message I said: When I read the exception, it seams the exception is thrown when ActiveReports’ CustomPrintDialog is passing its settings to System.Drawing.Printing.PrinterSettings.



    So I added a custom print procedure:







    Dim printDialog As New PrintDialog







    printDialog.AllowSomePages = True



    printDialog.PrinterSettings.FromPage = 1



    printDialog.PrinterSettings.ToPage = vwrViewer.Document.Pages.Count







    If printDialog.ShowDialog = Windows.Forms.DialogResult.OK Then







    vwrViewer.Document.Printer.PrinterSettings = printDialog.PrinterSettings







    If printDialog.PrinterSettings.PrintRange = Printing.PrintRange.SomePages Then



    vwrViewer.Document.Printer.PrinterSettings.FromPage = printDialog.PrinterSettings.FromPage



    vwrViewer.Document.Printer.PrinterSettings.ToPage = printDialog.PrinterSettings.ToPage



    End If







    vwrViewer.Print(False, False)







    End If







    After using this solution for a week, there have been no complains about the error.







    Beste regards,



    Willem



    [/activereports_archive]

  • Posted 14 September 2017, 9:29 am EST

    [activereports_archive]Hello,







    It seems that your issue has been resolved, hence considering this forum as closed.



    In case you face any further issues, feel free to contact us and we would be glad to assist you in the same.







    Regards,



    Mohita[/activereports_archive]

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels