Skip to Content
0

SAPBusinessObjects.WPF.Viewer throwing NullReferenceException

May 04, 2017 at 07:27 PM

115

avatar image
Former Member

Hi all,

Here is my situation. I have a new .rpt and corresponding .cs file. I have a WPF app. In the Loaded handler of my user control that has nothing more than a grid and the CR WPF viewer on it, I'm running the following code:

private void InspectionReportView_Loaded(object sender, System.Windows.RoutedEventArgs e)

{

try

{

var context = DataContext as InspectionViewModel;

ReportDocument report = new ReportDocument();

var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;

report.Load(Path.Combine(currentDirectory, "../../Reports/InspectionReport1.rpt"));

var dataSet = ReportManager.GetInspectionReportDataSet();

report.SetDataSource(dataSet);

_viewer.ViewerCore.ReportSource = report;

}

catch

(Exception ex)

{ string msg = ex.Message; }

}

Here is the XAML for my UserControl:

http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d=" http://schemas.microsoft.com/expression/blend/2008" xmlns:cr="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer" xmlns:local="clr-namespace:SunNuclear.Detection.Radon1030.UI.Reports" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="500">

<Grid>

<cr:CrystalReportsViewer x:Name="_viewer" HorizontalAlignment="Left" Margin="-14,0,0,0" VerticalAlignment="Top" Height="209" Width="531"/>

</Grid>

</UserControl>

I have added the following to my App.config:

<startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup>

My initial report uses a DataSet with around 6 tables in it. I load the data set up and pass it to the report via SetDataSource. When the report viewer constantly choked, I created a new .rpt and a new DataSet. The new report has one field. The DataSet has one table with one column (type string). I decided to get one field displaying. I add a row to the DataSet table, populate the value and pass it to the report. Still the viewer is throwing a NullReferenceException. I can't get a simpler example yet it still doesn't work. Please help!! Deadline looming :|

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member May 08, 2017 at 04:51 PM
0

So I know you are all sitting there on pins and needles waiting for the answer on this one so I'll tell you what I did.

I WAS using the NuGet package for CR (VS2015) in my project. Of course I had the CR Runtime and CR For VS. For whatever reason, I removed the NuGet package and then added a new report to my project. This caused the references for CR to be added to my project. Then things worked. I can only assume there was a mismatched version of the dll's for which the report was developed in and what it was being generated in. Does anyone have anything to add to this?

The exception thrown out of the SAPBusinessObjects.WPF.Viewer dll was simply a NullReferenceException. There was no visibility into what caused the exception. Very vague and close to impossible to determine root cause.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 08, 2017 at 12:28 PM
0

Is anyone out there listening? I'm getting ready to scrap any plan to use Crystal Reports. Any help would be appreciated.

Share
10 |10000 characters needed characters left characters exceeded