Hi guys. I have a problem deserializing XML files. The deserialization must be done in a For Loop, but it gives me an IOException saying that the file is used by another process. This happens only when I try to deserialize XML files in a For Loop. When not in loop, it deserializes the XML normally. What can cause the problem here? Here's my code:

vb.net Code:
  1. Public Sub Form1_Load(ByVal sender as Object, ByVal e as EventArgs) Handles Me.Load
  2.  Dim path As String = AppDataPath & "\D01 Software Manager\XML"
  3.         If IO.Directory.Exists(path) = True Then
  4.             Dim intIndex As Integer = 0
  5.             For Each strFile As String In GetFiles(path)
  6.                 Dim bar As New ProgramBar
  7.                 bar.ID = intIndex
  8.                 bar.Info = LoadInfo(strFile, GetType(ProgramInfo))
  9.                 'bar.picIcon.Image = ReturnIcon(bar.Info.exe, 0).ToBitmap
  10.                 barList.Add(bar)
  11.                 intIndex += 1
  12.             Next
  13.         End If
  14.         If barList.Count <> 0 Then
  15.             For Each bar As ProgramBar In barList
  16.                 Me.Controls.Add(bar)
  17.                 bar.Location = New Point(20, 200)
  18.                 bar.Size = New Size(544, 100)
  19.                 bar.Parent = FlowLayoutPanel1
  20.             Next
  21.         Else
  22.             Dim lblInfo As New Label
  23.             lblInfo.ForeColor = Color.Gray
  24.             lblInfo.BackColor = Color.Transparent
  25.             lblInfo.Text = "You don't have programs from D01 MicroApps."
  26.             Me.Controls.Add(lblInfo)
  27.             lblInfo.Parent = FlowLayoutPanel1
  28.             lblInfo.AutoSize = True
  29.         End If
  30. End Sub
  31.  
  32. Public Shared Function LoadInfo(ByVal filename As String, ByVal newType As Type) As Object
  33.         'Does the file exist?
  34.         Dim fileInfo As New FileInfo(filename)
  35.         If fileInfo.Exists = False Then
  36.             'create a blank version of the object and return that..
  37.             Return System.Activator.CreateInstance(newType)
  38.         End If
  39.         'open the file
  40.         Dim stream As New FileStream(filename, FileMode.Open)
  41.         'load the object from the stream..
  42.         Dim newObject As Object = LoadInfo(filename, newType)
  43.         'Close the stream
  44.         stream.Close()
  45.         'return the object..
  46.         Return newObject
  47.     End Function
  48.  
  49.     'Load-actually perform the deserialization
  50.     Public Shared Function LoadInfo(ByVal stream As Stream, ByVal newType As Type) As Object
  51.         'create a serializer and load the object..
  52.         Dim serializer As New XmlSerializer(newType)
  53.         Dim newObject As Object = serializer.Deserialize(stream)
  54.         'return the new object
  55.         Return newObject
  56.     End Function