Illegal action on a disposed object \\ null reference exception
Posted: Thu Jul 29, 2021 10:16 am
Hi!
I am getting an exception when changing between views. I am using MVVM and Arction 10.0.1.4001.
On my main page I have a UserControl with binding of ViewXY:
<UserControl x:Class="CommonModules.Presentation.UserControls.Course"
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/marku ... ility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:lcusb="http://schemas.arction.com/ChartingMVVM/ultimate/"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<lcusb:LightningChart
x:Name="CourseGraph"
ViewXY="{Binding CoursePlot}">
</lcusb:LightningChart>
I am changing the DataContext in the main page with:
<CommonUserControls:Course
DataContext="{Binding CourseViewModelInstance}">
</CommonUserControls:Course>
It works fine when loading the main page for the first time. But when I go the next page and then back again (FYI: I am using INavigationService), the program gets the following exceptions, because I am trying to access the CoursePlot instance, which is disposed:
Info gathered from the ChartMessage subscription:
First Exception:
"Illegal action on a disposed object detected."
"Illegal parent setting of disposed object detected"
Second Exception:
Arction.Wpf.ChartingMVVM.MessageSeverity.RecoverableError
"Catched a null reference exception."
"Object reference not set to an instance of an object."
with the chart info:
"\r\n\r\n----------CHART INFORMATION----------\r\nCreatedCount: 12\r\nAliveCount: 11\r\nDisposedCount: 1\r\nUndisposedCount: 0\r\nId: 10\r\nLicenseStatus: 1\r\nVersion: 10.0.1.4001\r\nNagText: No valid license available.\r\nLastErrorHandled: True\r\nThrowChartErrorsEnabled: False\r\nDeploymentKeyChanged: True\r\nDebuggerAttached: True\r\nIsDPIAware: True\r\nRenderOptions: \r\nRenderDevice: Description: NVIDIA NVS 310\n\nRenderer device type: DX11 Hardware\nFeature level: DX_11_0\nMax Anti Alias Level: 8\nVendor ID: 0x10de\nRender device created: Yes\nPure device: Yes\nFast vertex format: No\nHardware vertex processing: Yes\nAnti-aliasing: Yes\nShader model 3: Yes\nIndex buffers: 32-bit\nD2D v1.1 supported: Yes\nSupport arbitrary texture size: No\nD3DImage used on drawing: No\nTexture max size (WxH): 16384x16384\nSoftware DPI aware: True\nDPI scaling factor: X: 96 (100.0%) Y: 96 (100.0%) \nMemory on graphics card: 462 MB\nAll GPUs in system: \nNVIDIA NVS 310\nNVIDIA NVS 310\nMicrosoft Basic Render Driver\nActive objects: \r\nEngineInitResults\r\nLast Engine Init Results:\n\tDate Time: 29-Jul-21 11:59:02 AM\n\tDevice Type: HardwareOnlyD11\n\tSuccess: True\n\tWarnings: None\n\tExceptions: None\n\r\nPixelAlignmentOffsetIsFinal: True\r\nPixelAlignmentOffset: \r\nIsPixelAlignmentOn: True\r\nIsPixelAlignmentOK: True\r\nChartScreenPosition: \r\nChartWidth: 786\r\nChartHeight: 315.666666666667\r\nActiveView: ViewXY"
System.NullReferenceException: 'Object reference not set to an instance of an object.'
I was able to resolve the issue by adding following line to the code behind:
CourseGraph.ViewXY = new ViewXY();
After adding that, I don't get the exceptions from above...
-> But then my Graphs keeps being empty and the binding doesn't work anymore
Usually
var viewModel = (CourseViewModel)DataContext;
viewModel.CoursetPlot = CourseGraph.ViewXY;
would work, but since the DataContext is null, when the usercontrol is being initialzed, it can't work. One workaround is to set the ViewXY at a later time, which I was able to do within the chartmessage subscription method. But thats really bad practice.
Can someone please help me?
Best regards
I am getting an exception when changing between views. I am using MVVM and Arction 10.0.1.4001.
On my main page I have a UserControl with binding of ViewXY:
<UserControl x:Class="CommonModules.Presentation.UserControls.Course"
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/marku ... ility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:lcusb="http://schemas.arction.com/ChartingMVVM/ultimate/"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<lcusb:LightningChart
x:Name="CourseGraph"
ViewXY="{Binding CoursePlot}">
</lcusb:LightningChart>
I am changing the DataContext in the main page with:
<CommonUserControls:Course
DataContext="{Binding CourseViewModelInstance}">
</CommonUserControls:Course>
It works fine when loading the main page for the first time. But when I go the next page and then back again (FYI: I am using INavigationService), the program gets the following exceptions, because I am trying to access the CoursePlot instance, which is disposed:
Info gathered from the ChartMessage subscription:
First Exception:
"Illegal action on a disposed object detected."
"Illegal parent setting of disposed object detected"
Second Exception:
Arction.Wpf.ChartingMVVM.MessageSeverity.RecoverableError
"Catched a null reference exception."
"Object reference not set to an instance of an object."
with the chart info:
"\r\n\r\n----------CHART INFORMATION----------\r\nCreatedCount: 12\r\nAliveCount: 11\r\nDisposedCount: 1\r\nUndisposedCount: 0\r\nId: 10\r\nLicenseStatus: 1\r\nVersion: 10.0.1.4001\r\nNagText: No valid license available.\r\nLastErrorHandled: True\r\nThrowChartErrorsEnabled: False\r\nDeploymentKeyChanged: True\r\nDebuggerAttached: True\r\nIsDPIAware: True\r\nRenderOptions: \r\nRenderDevice: Description: NVIDIA NVS 310\n\nRenderer device type: DX11 Hardware\nFeature level: DX_11_0\nMax Anti Alias Level: 8\nVendor ID: 0x10de\nRender device created: Yes\nPure device: Yes\nFast vertex format: No\nHardware vertex processing: Yes\nAnti-aliasing: Yes\nShader model 3: Yes\nIndex buffers: 32-bit\nD2D v1.1 supported: Yes\nSupport arbitrary texture size: No\nD3DImage used on drawing: No\nTexture max size (WxH): 16384x16384\nSoftware DPI aware: True\nDPI scaling factor: X: 96 (100.0%) Y: 96 (100.0%) \nMemory on graphics card: 462 MB\nAll GPUs in system: \nNVIDIA NVS 310\nNVIDIA NVS 310\nMicrosoft Basic Render Driver\nActive objects: \r\nEngineInitResults\r\nLast Engine Init Results:\n\tDate Time: 29-Jul-21 11:59:02 AM\n\tDevice Type: HardwareOnlyD11\n\tSuccess: True\n\tWarnings: None\n\tExceptions: None\n\r\nPixelAlignmentOffsetIsFinal: True\r\nPixelAlignmentOffset: \r\nIsPixelAlignmentOn: True\r\nIsPixelAlignmentOK: True\r\nChartScreenPosition: \r\nChartWidth: 786\r\nChartHeight: 315.666666666667\r\nActiveView: ViewXY"
System.NullReferenceException: 'Object reference not set to an instance of an object.'
I was able to resolve the issue by adding following line to the code behind:
CourseGraph.ViewXY = new ViewXY();
After adding that, I don't get the exceptions from above...
-> But then my Graphs keeps being empty and the binding doesn't work anymore
Usually
var viewModel = (CourseViewModel)DataContext;
viewModel.CoursetPlot = CourseGraph.ViewXY;
would work, but since the DataContext is null, when the usercontrol is being initialzed, it can't work. One workaround is to set the ViewXY at a later time, which I was able to do within the chartmessage subscription method. But thats really bad practice.
Can someone please help me?
Best regards