Hello everybody,
I've written an WPF application on Visual Studio 2019 at work, where this really weired error sometimes (1) appears.
(1) This unhandled exception may appear, where the earliest time was under a minute,
and the latest one was over 3 1/2 hours, however, sometimes this exception may also
not appear during on test runs.
In my application I've some XYChart objects to display different LineSeries data of type double. The axes are able
to do an auto refresh (2) with a new minimum and maximum boundary.
(2) A month ago I had opened a topic about that old issue, which already has been solved.
However, when I got this unhandled exception, Visual Studio tells me, that this appeared somewhere in
ActiproSoftware.Charts.Wpf.dll and I don't have the required .pdb file, which might be helpful.
The basic "reason" is just "System.InvalidOperationException: Type 'System.Double' is not supported."
Here is a snippet, where this "unhandled" exception could appear, maybe not:
Dispatcher.Invoke(() => {
try {
/* removing previous LineSeries */
chartRight.Series.Clear();
/* receiving new LineSeries object */
LineSeries currentSeries = CurrentLineSeries(new List<Coordinates>(liveData.DataCollection), ChartSelector.ChartRight);
chartRight.Series.Add(currentSeries);
/* --- auto refresh for my axis --- */
/* Could this be the cause of the exception?
*
* Since the base class XYAxisBase doesn't comes with properties to setting up
* the minimal and maximal value for my axes, a conversion to XYDoubleAxis
* allows me to do this.
*/
XYDoubleAxis xyDA = (XYDoubleAxis)chartRight.YAxes.First();
xyDA.Minimum = Convert.ToDouble(currentLiveData.MinValue);
xyDA.Maximum = Convert.ToDouble(currentLiveData.MaxValue);
/* here the tick ranges for my XYaxis are going to refresh */
axisBoundaries[ChartSelector.ChartRight].MinimalValue = Convert.ToInt32(currentLiveData.MinValue);
axisBoundaries[ChartSelector.ChartRight].MaximalValue = Convert.ToInt32(currentLiveData.MaxValue);
SetStepRanges(ref xyDA, axisBoundaries[ChartSelector.ChartRight]);
chartRight.Refresh();
} catch (Exception e) {
/* unlike the exception shall be handled here, it won't */
Console.Error.WriteLine("{0}{1}{2}, e.Message, Environment.NewLine, e.StackTrace");
if (e is InvalidOperationException ioe) {
/* since the exception is marked as "unhandled", I never get a more clear information about
where, when and why this happens
*/
using(LogOutput lo = new LogOutput()) {
lo.WriteToLog(String.Format("HRESULT: {0}, SOURCE: {1}{2}", ioe.HResult, ioe.Source, Environment.NewLine), LogState.DEBUG);
}
if (ioe.Data != null) {
foreach(Object o in ioe.Data) {
Console.Error.WriteLine(o);
using(LogOutput lo = new LogOutput()) {
lo.FullPathLogFile = AbsLogPath;
lo.WriteToLog(o.ToString(), LogState.DEBUG);
}
}
}
}
}
}, DispatcherPriority.Render);
CurrentLiveData() function:
private LineSeries CurrentLiveData(List<Coordinates> dataSource, ChartSelector chartSide) {
LineSeries ls = new LineSeries() {
XPath = "X",
YPath = "Y",
ItemsSource = dataSource
};
if (chartSide == ChartSelector.ChartLeft) {
ls.LineKind = XYSeriesLineKind.Step;
} else {
ls.LineKind = XYSeriesLineKind.Spline;
}
return ls;
}
SetStepRanges() function:
private void SetStepRanges(ref XYDoubleAxis axis, AxisBoundary boundarySource, bool isXAxis = false) {
double majorInterval;
double minorInterval;
try {
/* determining step ranges for charts */
switch(boundarySource.RangeDetector) {
case BoundaryRange.Steps10:
majorInterval = Convert.ToDouble(1);
minorInterval = Convert.ToDouble(0);
break;
case BoundaryRange.Steps20:
/* ... */
break;
/* ... */
case BoundaryRange.Steps25000:
majorInterval = Convert.ToDouble(5000);
minorInterval = Convert.ToDouble(2500);
break;
default:
majorInterval = Convert.ToDouble(10000);
minorInterval = Convert.ToDouble(5000);
break;
}
} catch (Exception e) {
Console.Error.WriteLine("{0}{1}{2}, e.Message, Environment.NewLine, e.StackTrace");
}
axis.TickMajorInterval = majorInterval;
axis.TickMinorInterval = minorInterval;
}
The given stack trace by Visual Studio is also unclear for me:
Unhandled exception: System.InvalidOperationException: Type 'System.Double' is not supported.
at ActiproSoftware.Windows.Controls.Charts.Primitives.DataTypeHelper.Average(Object average, Int32 count, Object newValue)
at ActiproSoftware.Windows.Controls.Charts.XYDataPointCollectionView.<CreateDataPointsWithoutResolvedValues>d__45.MoveNext()
at ActiproSoftware.Windows.Controls.Charts.XYDataPointCollectionView.P20(IEnumerable`1 )
at ActiproSoftware.Windows.Controls.Charts.XYDataPointCollectionView.Initialize()
at ActiproSoftware.Windows.Controls.Charts.Primitives.XYSeriesBase.PrepareSeries(IXYAxisPlotter primaryAxis, IXYAxisPlotter secondaryAxis, Size plotSize)
at ActiproSoftware.Windows.Controls.Charts.Primitives.XYChartPlotter.XDQ(Size )
at ActiproSoftware.Windows.Controls.Charts.Primitives.XYChartPlotter.Prepare(Size plotSize)
at ActiproSoftware.Windows.Controls.Charts.Primitives.ChartPanel.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at test.App.Main()
The application "[18184] test.exe" has been terminated with code 0 (0x0).
Can you figure out what's wrong here?
It that a possible bug in your API?