This is a migrated thread and some comments may be shown as answers.

Window Open InitializeComponent Error

1 Answer 32 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Psyduck asked on 16 Dec 2020, 01:51 PM

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.

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 21 Dec 2020, 10:17 AM

Hello Kim

I am sorry to hear that you are experiencing an issue with our product.

Can you please check if all Telerik Reporting references are from the same version? You may test to run the Upgrade Wizard. To be able to investigate further, can you please attach a Trace Listener to the configuration file of the project and send us the generated log? It might provide additional information about the issue.

You can also consider sending us the problematic application, so we can test it locally.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Answers by
Neli
Telerik team
Share this question
or