Profile Picture

NullReferenceException in NChartControl.Panels

Posted By Ereona 12 Years Ago
Author
Message
Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Erena,

That pretty much depends on the way you interact with the control from concurrent threads, however as a general rule you can lock the chart document when you modify its state concurrently:

nChartControl1.Document.Lock();

// changes to the document go here

nChartControl1.Document.Unlock();

this will ensure that the control painting, which occurs in the main UI thread does not interfere with changes you make to the chart document from other threads.

Regarding the exception - check all code that assigns a chart document and loads a document from storage (stream file etc.).



Best Regards,
Nevron Support Team



Ereona
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 43, Visits: 1
Thank you for reply. You're right, chartControl.Document is null. But I don't know in which methods of NChartControl class it could become null. Could you give me an advice which parts of code I need to lock?

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Ereona,

Yes that may be caused by threading in which case you should ensure the chart is accessed properly by threads. To narrow the problem you can check which one of the following is null:

chartControl.Document

chartControl.Document.RootPanel

however you still need to ensure the control is modified in a synchronous fashion as it is not thread safe. Let us know if you meet any problems.



Best Regards,
Nevron Support Team



Ereona
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 43, Visits: 1
It reproduces not every time. I think it is related with threads. Unfortunately I'm not able to post all code here.

Here are exception details:

System.NullReferenceException was unhandled
Message=Ссылка на объект не указывает на экземпляр объекта.
Source=Nevron.Chart.WinForm
StackTrace:
в Nevron.Chart.WinForm.NChartControl.get_Panels()
в ChartsProject.GraphUpdaters.AxisUpdateOperations.LastPointLabelUpdateOperation.removeAnnotationById(Int32 panelId) в C:\ChartsProject\GraphUpdaters\AxisUpdateOperations\LastPointLabelUpdateOperation.cs:строка 167
в ChartsProject.GraphUpdaters.AxisUpdateOperations.LastPointLabelUpdateOperation.setAnnotationToPointOnLine(NLineSeries line, Int32 pointIndex, Int32 annotationId) в C:\ChartsProject\GraphUpdaters\AxisUpdateOperations\LastPointLabelUpdateOperation.cs:строка 123
в ChartsProject.GraphUpdaters.AxisUpdateOperations.LastPointLabelUpdateOperation.performUpdate(NAxis chartAxis, IObject axisObject) в C:\ChartsProject\GraphUpdaters\AxisUpdateOperations\LastPointLabelUpdateOperation.cs:строка 75
в ChartsProject.GraphUpdaters.CAxisUpdater.updateComponent() в C:\ChartsProject\GraphUpdaters\CAxisUpdater.cs:строка 45
в ChartsProject.GraphUpdaters.CFullGraphViewUpdater.performUpdate() в C:\ChartsProject\GraphUpdaters\CFullGraphViewUpdater.cs:строка 53
в ChartsProject.CGraphView.UpdateChartProperties(IObject currentObject) в C:\ChartsProject\CGraphView.cs:строка 383
в ChartsProject.CIntermediateGraphView.invokePropertyUpdateInMainThread(MMEDataViewObject dataViewObject) в C:\ChartsProject\CIntermediateGraphView.cs:строка 192
в ChartsProject.CIntermediateGraphView.getDataCallback(IAsyncResult ar) в C:\ChartsProject\CIntermediateGraphView.cs:строка 169
в System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)
в System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
в System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()
в System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
в System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
в System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
в System.Threading.ThreadPoolWorkQueue.Dispatch()
в System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
InnerException:

Here is the part of Disassembly, cursor is on the line 00000044. Maybe it helps you to understand the reason for the exception.
NPanelCollection panels = _chartControl.Panels;
00000044 mov eax,dword ptr [ebp-3Ch]
00000047 mov ecx,dword ptr [eax+4]
0000004a mov eax,dword ptr [ecx]
0000004c mov eax,dword ptr [eax+000000CCh]
00000052 call dword ptr [eax+1Ch]
00000055 mov dword ptr [ebp-50h],eax
00000058 mov eax,dword ptr [ebp-50h]
0000005b mov dword ptr [ebp-44h],eax

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Ereona,

Can you send us a code snippet that replicates the problem - it is highly unusual that you get this exception from this property. Also can you post stack trace?



Best Regards,
Nevron Support Team



Ereona
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 43, Visits: 1
Hello.
Sometimes I have NullReferenceException while trying to get the value of NChartControl.Panels property. What could be the reason for this?
I'm not sure but maybe it happens since we began to use 2012 year version (12.4.9.12).



Similar Topics


Reading This Topic