I am in the process of converting my working VB 2010 forms application to Visual Studio 2013. I've encountered a nullreferenceexception where one does not occur in the old code. Basically, I start with a fresh instance of the form. The form contains a treeview and the user can navigate down through it and select a node. Based on their selection another portion of the form gets populated (a datagridview) with the associated elements. This is an explore screen.
When the user is done exploring, the application captures the node they were on and saves it. Immediately, the form is closed, disposed and set to nothing (NULL).
' Class variable definition
Private XInvenNode As New TreeNode
If fdiaXInven Is Nothing Then fdiaXInven = New diaExploreInven(True, True)
fdiaXInven.tvInven.SelectedNode = XInvenNode
fdiaXInven.ShowDialog()
XInvenNode = .tvInven.SelectedNode
results = .SelectedItems
fdiaXInven.Close()
fdiaXInven.Dispose()
fdiaXInven = Nothing
If the user returns to the explorer screen in the same session, it is instantiated again and the saved tree node is supposed to be restored so the user can continuing exploring in the same area. This is when the nullreferenceexception occurs.
I found this link and understand what a nullreferenceexception is. I've set breakpoints in the code and analyzed the contents of the variables within fdiaInven. It is not Nothing or NULL! For example, the following code worked perfectly on the first pass through but failed the second time:
fdiaInven.tvInven.SelectedNode = XInvenNode
What am I missing here? Are there some new rules in VB since the 2010 version that would cause this?