SAP Knowledge Base Article - Public

1626917 - Error when initiating a WPF Application using Crystal Report WPF viewer

Symptom

  • A Shell Start-up project shows loading screen
  • Main window containing the CR WPF viewer is loaded on completion of load of the Start-up project
  • This results in the error:

Object reference not set to an instance of an object

  • Or:

NullRefrenceException … at SAPBusinessObjects.WPF.Viewer.ViewerCore.c__DisplayClass1.<set_ReportSource>b__0()

Environment

  • VS2010
  • Crystal Reports for Visual Studio 2010

Resolution

  • Use the following approach
  • Shell Start-up application code:
Application app = new Application();
//Application main window 
// Launch host from MainWindow
app.Run( new MainWindow()); 
private void button1_Click(object sender, RoutedEventArgs e)
{
System.Windows.Window viewer = new MyWpfViewerHost();
viewer.Show();
}
  • WPF application code:
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
// crViewer is SAPBusinessObjects.WPF.Viewer.CrystalReportsViewer
// Assign report to viewer
crViewer.ViewerCore.ReportSource = new CrystalReport1();
}
}

See Also

Keywords

CR2010 2010 CR4VS2010 CR4VS VS2010 NET2010 Crystal Reports for .NET Framework 4.0 crforvs 13 Crystal Reports for Visual Studio 2010 , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio