Hello. I am posting a question like this because I keep getting errors while using the report.
This problem only occurs on the project I am currently working on.
"An exception of type 'System.NullReferenceException' occurred in
PresentationFramework.dll but was not handled in user code Additional information
: Object reference not set to an instance of an object."
When creating a new project with the same reference, no error appears.
What is the problem? Leave the sauce below.
Telerik 2020.3.915.40 Version References(7)
Telerik.Windows.Controls Telerik.Windows.Controls.Chart Telerik.Windows.Controls.Data Telerik.Windows.Controls.GridView
Telerik.Windows.Controls.Input Telerik.Windows.Controls.Navigation Telerik.Windows.Data
TelerikReporting 14.2.20.916 Version References(5)
Telerik.Reporting Telerik.Reporting.OpenXmlRendering Telerik.Reporting.OpenXmlRendering Telerik.ReportViewer.Wpf Telerik.ReportViewer.Wpf.Themes
=Xaml======================================================================================
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/SKC_QTO;component/Plugin/Themes/Report/System.Windows.xaml" />
<ResourceDictionary Source="pack://application:,,,/SKC_QTO;component/Plugin/Themes/Report/Telerik.Windows.Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/SKC_QTO;component/Plugin/Themes/Report/Telerik.Windows.Controls.Input.xaml" />
<ResourceDictionary Source="pack://application:,,,/SKC_QTO;component/Plugin/Themes/Report/Telerik.Windows.Controls.Navigation.xaml" />
<ResourceDictionary Source="pack://application:,,,/SKC_QTO;component/Plugin/Themes/Report/Telerik.ReportViewer.Wpf.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button x:Name="ChangeReportButton" Grid.Row="0" Height="30" Width="100" Command="{Binding ThisCommand}" Content="Change Report" Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" >
</Button>
<tr:ReportViewer Grid.Row="1" x:Name="ReportViewer1" HorizontalAlignment="Stretch" ReportSource="{Binding MyReportSource}">
</tr:ReportViewer>
</Grid>
=Xaml.cs======================================================================================
public partial class ReportingView : Window
{
internal const string TelerikVersion = "2020.3.915.40";
internal const string TelerikPublicKeyToken = "~~~~~~~~~~";
internal const string Culture = "~~~~~~";
public ReportingView()
{
// This is for testing purposes. Assembly is initially registered at startup.
Assembly.Load($"Telerik.Windows.Controls, Version={TelerikVersion}, Culture={Culture}, PublicKeyToken={TelerikPublicKeyToken}");
Assembly.Load($"Telerik.Windows.Controls.Chart, Version={TelerikVersion}, Culture={Culture}, PublicKeyToken={TelerikPublicKeyToken}");
Assembly.Load($"Telerik.Windows.Controls.Data, Version={TelerikVersion}, Culture={Culture}, PublicKeyToken={TelerikPublicKeyToken}");
Assembly.Load($"Telerik.Windows.Controls.GridView, Version={TelerikVersion}, Culture={Culture}, PublicKeyToken={TelerikPublicKeyToken}");
Assembly.Load($"Telerik.Windows.Controls.Input, Version={TelerikVersion}, Culture={Culture}, PublicKeyToken={TelerikPublicKeyToken}");
Assembly.Load($"Telerik.Windows.Controls.Navigation, Version={TelerikVersion}, Culture={Culture}, PublicKeyToken={TelerikPublicKeyToken}");
Assembly.Load($"Telerik.Windows.Data, Version={TelerikVersion}, Culture={Culture}, PublicKeyToken={TelerikPublicKeyToken}");
InitializeComponent(); <<<<< This Error ★★★★★★★★★★
this.DataContext = new ViewModel();
//DataContext = new ReportingViewModel();
}
}
=ViewModel.cs======================================================================================
class ViewModel : INotifyPropertyChanged
{
private int testCounter = 0;
public event PropertyChangedEventHandler PropertyChanged;
Telerik.Reporting.ReportSource _myReportSource;
public Telerik.Reporting.ReportSource MyReportSource
{
get { return this._myReportSource; }
set
{
if (this._myReportSource != value)
{
this._myReportSource = value;
if (null != this.PropertyChanged)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("MyReportSource"));
}
}
}
}
public ViewModel()
{
this.MyReportSource = new InstanceReportSource { ReportDocument = null };
_thisCommand = new Telerik.Windows.Controls.DelegateCommand(x => ChangeReport());
}
ICommand _thisCommand;
public ICommand ThisCommand
{
get
{
return _thisCommand;
}
}
public void ChangeReport()
{
if (testCounter % 2 == 1)
this.MyReportSource = new InstanceReportSource { ReportDocument = new Report1() };
else
this.MyReportSource = new InstanceReportSource { ReportDocument = null };
testCounter++;
}
============================================================================================
Thanks.