Variable 'loNode' is used before it has been assigned a value. A null reference exception could result at runtime.


does anyone know why I am getting this error?

Imports System.Xml
Module Module1

    Sub Main()
        Dim doc As New XmlDocument
        Dim loNode As XmlNode
        Dim nodes As XmlNodeList
        doc.Load("C:\Desktop\Template.xml")
        nodes = doc.SelectNodes("program/databaseinfo")
        loNode.SelectSingleNode("programshortname").InnerText = "PCF"
        doc.Save("C:\New.xml")

        loNode = Nothing
        doc = Nothing

    End Sub

End Module

Recommended Answers

All 2 Replies

in line 10 you use an attribute of loNode. Where did you set loNode to anything?

try changing statement

Dim loNode As XmlNode

at line 6 to

Dim loNode As XmlNode = nothing
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.