releasing a system reource for XmlTextReader

I am working with a windows forms application.
I am working with some VB.Net code that has been audited by some auditing software. The auditing software has an issue  with the function below, and references line 37.  Can someone tell me what the problem might be here, and how I can fix it?

the function getFrmFromXML() in TrosiController.vb sometimes fails to release a system resource allocated by XmlTextReader() on line 37

33 Public Function getFrmFromXML(ByVal strVal As String, ByVal strNavPath As String) As String()

34  Dim retVal(4) As String
35  Try
36  Dim txtReader As System.Xml.XmlReader
37  txtReader = new XmlTextReader(strNavPath)
38  txtReader.Read()

39   While txtReader.Read()

40   Dim nType As XmlNodeType = txtReader.NodeType

41    'move to fist element
42    txtReader.MoveToElement()
43    If nType = XmlNodeType.Element Then
44    If txtReader.Name ="treeItem" Then
45        If (strVal = txtReader.GetAttribute(1)) Then
46          retVal(0) = txtReader.GetAttribute(0).ToString()
47          retVal(1) = txtReader.GetAttribute(1).ToString()
48          Exit While
49    End If
50   End If
51   End If
52   End While
53  Catch ex As Exception
54  Throw(ex)
55  End Try
56  return retVal
57  End Function
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
I'm not sure how the auditing software determines this fact exactly but in general you can avoid such problems (and maybe the audit warning) with the Using statement:
            Using txtReader As System.Xml.XmlReader = New XmlTextReader(strNavPath)

                ' . . . your code . . .

            End Using

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
awesome, thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.