Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.Net XMLTextWriter无法访问文件,因为该文件正在使用中?_Xml_Vb.net_Writer - Fatal编程技术网

VB.Net XMLTextWriter无法访问文件,因为该文件正在使用中?

VB.Net XMLTextWriter无法访问文件,因为该文件正在使用中?,xml,vb.net,writer,Xml,Vb.net,Writer,我正在编写一个自动更新函数,从XML读取客户端版本,然后在修补一些文件后,XMLTextWriter应该更新客户端版本,但每当我尝试创建TextWriter时,我都会被告知,即使我关闭了读卡器,该文件仍在使用中。我错过了什么 'pulling in reader from xml' Dim clientReader As XmlReader = XmlReader.Create("launch.xml") 'Read the XML files to determine th

我正在编写一个自动更新函数,从XML读取客户端版本,然后在修补一些文件后,XMLTextWriter应该更新客户端版本,但每当我尝试创建TextWriter时,我都会被告知,即使我关闭了读卡器,该文件仍在使用中。我错过了什么

  '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)

try设置可能重复为nothing:clientReader=nothing服务器阅读器=nothing@jdweng我试了一下。另一个进程仍在使用该文件。两个对象都有ReadState()。确定读取状态:Closed、EndOfFile、Error、Initial、Interactive。我检查了ReadState,它在关闭前列为Interactive,在使用Close()时列为Closed。当读卡器设置为Nothing时,我得到一个NullReferenceException