cancel
Showing results for 
Search instead for 
Did you mean: 

WPF report viewer throws exception when print button clicked when hosted on winform

Former Member
0 Kudos

When hosted in a winform app the wpf report viewer control throws an exception when the print button is clicked.

All the other buttons appear to work, any ideas on a work round?

I have created a sample VS 2013 solution that shows this issue

As I can't even attach a renamed zip file it can be downloaded directly from here: http://1drv.ms/QxUrZo

The reason I am attempting to use this control is that the standard reportviewer causes occasional errors in citrix enviroments causing the citrix session to lock up.  This appears to be a relatively common issue and the usual issue of both sides (citrix & crystal) blaming the other for the cause and me the developer needs to find a work round.

I've 'bodged' in an additional button on our app to export a loaded report to file as pdf then print it but this should not be the permanent resolution.

BTW glad to see the x64 dynamic parameter issue has been fixed at last, think I reported this over two years ago and again ended up having to work round it.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

I saw the comment in

However I was not clear on the WPF report viewer hosted on winform. Unfortunately, the WPF viewer is not supported in winforms. Please see KBA: 1544651 - Crystal Reports WPF Viewer fails with NullReferenceException when used in a WinForms appli...

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Former Member
0 Kudos

Hi the KBA you refer to actually references a different issue in that the control just does not work.

The WPF viewer works just fine when hosted in a winform app, apart from when you click the print button and you then get an exception.

I was hoping you might be able to provide a work round for the issue.

Don't suppose you have any ideas on the printing/preview issue with citrix which is the root of the issue our customers are having?

An example of other people having this issue can be found here:

http://scn.sap.com/thread/3222465

Was hoping to use the WPF viewer as a work round.

former_member183750
Active Contributor
0 Kudos

I actually was not aware that the WPF viewer works as well as it does in Winforms. If memory serves right, in SP 1 it did not work at all and that is where the KBA comes from (e.g.; it was released in 2010). And there was no word from Product Management or R&D that they did any work on it at all.

Anyhow, there is another Discussion on the same issue here:

See my last response there. If I can get something like that, I'll see about testing and giving R&D a ping re possibility of them looking at it.

- Ludek

Former Member
0 Kudos

Hi Ludek

A sample project that loads a simple report is available from here: http://1drv.ms/QxUrZo

The project is called WPFReportHost

This loads a simple report when run then you can test the basic functionality of the viewer and all will work until you press the print button and then you get the application crash.

Have to improve my search technique when I googled for other people having this issue I didnt' find the link.

We've noticed the WPF viewer loads considerably faster and has better functionality than the winform viewer and hope that it might solve the citrix preview issue (yet to be tested).

So as a work round we've hidden the default print button added our own and call the report print directly as per below:

using (PrintDialog dialog = new PrintDialog())           

  {               

     dialog.AllowCurrentPage = true;

     dialog.AllowSelection = true;    

     dialog.AllowSomePages = true;

     dialog.AllowPrintToFile = true;

     if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)                     {

          reportDocument.PrintToPrinter(                         

               dialog.PrinterSettings,                         

               new System.Drawing.Printing.PageSettings(dialog.PrinterSettings);

                false);                   

     }               

}           

Would be nice to have a fix

former_member183750
Active Contributor
0 Kudos

Hi Barney

Many thanks. I will look at the project later today or Monday.

- Ludek

Answers (0)