Error null Reference when adding two instances of the control to the page

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
maysamdata
Posts: 4
Joined: Mon Aug 06, 2018 4:14 pm

Error null Reference when adding two instances of the control to the page

Post by maysamdata » Mon Jan 24, 2022 6:25 am

When I add an instance of the WPF chart to a page, it draw the chart well and there is no problem, but when I add two or more instances of the chart to the page, the null reference error Gives. I use Arction LightningChart .NET v10.0.1.

Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code).
Arction.Wpf.Charting.ChartException: 'Catched a null reference exception.: Object reference not set to an instance of an object.'



Image

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Error null Reference when adding two instances of the control to the page

Post by ArctionKestutis » Mon Jan 24, 2022 8:48 am

It is unusual problem. We have many examples in our Demo, which uses more than 2 chart instances.
It is likely you are doing something unusual.
Two most common mistakes (made by LightningChart users) are Sharing objects and not Thread-safe chart update.
As described in User’s Manual chapter 28, Sharing objects between other objects in the same chart, or other chart instances, is not allowed. In most cases ChartMessage reports errors of invalid object sharing cases. Therefore, I would recommend subscribing to _Chart.ChartMessage event. We send a lot of important information through ChartMessage, which could give clues about the cause of the problem.
In addition, LightningChart requires that all the Chart properties should be updated in Main UI Thread. LightningChart should be updated in the Main Thread, as for the most UI controls. When using a background thread in the application, all UI updates from the thread must go through Invoke (Control.Invoke() in WinForms, and Dispatcher.Invoke() in WPF). If chart is not updated in Main Thread user may get very random and unexpected results (including crashes and access violation).

If above explanation did not resolved your problem, please verify issue with latest version of LightningChart® .NET library. After that you could send test project (to replicate issue) to our Support email address together with your subscription ID.

Hope this helps.

Post Reply