0

I am writing an auto-updating function that reads the client version from XML and then after patching some files, an XMLTextWriter should update the client version, but when ever I try to create the TextWriter I am being told that the file is still in use even though I close the readers. What am I missing?

  'pulling in reader from xml'

  Dim clientReader As XmlReader = XmlReader.Create("launch.xml")

    'Read the XML files to determine the server version'

    clientReader.ReadToFollowing("serverURL")
    Dim serverURL As String = clientReader.ReadElementContentAsString()
    Dim serverXMLpath As String = serverURL & "Updater/serverInfo.xml"
    Dim serverReader As XmlTextReader = New XmlTextReader(serverXMLpath)
    serverReader.ReadToFollowing("serverVer")
    Dim serverVer As Double = serverReader.ReadElementContentAsDouble()

    'Read client XML to determine clientVersion'
    clientReader.ReadToFollowing("clientVer")
    Dim clientVer As Double = clientReader.ReadElementContentAsDouble()

    'Determine what updates need to be downloaded'

    serverReader.ReadToFollowing("totalUpdates")
    Dim totalUpdates As Integer = serverReader.ReadElementContentAsInt()

    '.....'
    'files are downloaded and updated here'
    '.....'


    clientReader.Close()
    serverReader.Close()


    'change the client version!'
    Dim clientWriter As New XmlTextWriter("launch.xml", System.Text.Encoding.UTF8)
    'clientWriter.WriteElementString("clientVer", serverVer)
  • possible duplicate of [Why filestream not closed by xmlreader](http://stackoverflow.com/questions/9844978/why-filestream-not-closed-by-xmlreader) – JohnKiller Jul 06 '15 at 22:20
  • try setting to nothing : clientReader = nothing serverReader = nothing – jdweng Jul 06 '15 at 23:33
  • @jdweng I gave that a shot. The file is still being used by another process. – Nicholas A Dinio Jul 08 '15 at 00:36
  • Both object has a ReadState(). Determine what the read state is : Closed, EndOfFile, Error, Initial, Interactive. – jdweng Jul 08 '15 at 06:56
  • I checked the ReadState, it is listed as Interactive before closing and Closed when Close() is used. When the reader is set to Nothing, I am getting a NullReferenceException – Nicholas A Dinio Jul 20 '15 at 18:42

0 Answers0