title: A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll in windows 7 but not on xp
body: <p>I am having a bit of a problem with this code that works fine in Visual Basic 2010 Professional under Windows XP using .NET 4.0.  However, when this code runs on a Windows 7 machine, I get the following error:</p>
  <blockquote>
  <p>A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll</p>
  <p>&quot;An Unhandled Exception Of Type 'System.IO.IOException' Occurred In Mscorlib.dll&quot;</p>
  </blockquote>
  <p>The code I have written is used to write the content of a ListBox to a text file.</p>
  <p>The problem is that the file is not created or when it is created manually, it is not read from  and this only happens in Windows 7.</p>
  <p>This is the code I have written:</p>
  <pre><code>   'at the very top
     Imports System.Net
     Imports System
     Imports System.Windows.Forms
     Imports System.Security.Permissions
     
     'in my form load
     If My.Computer.FileSystem.FileExists(&quot;C:\hitory.txt&quot;) Then
          Dim h As New IO.StreamReader(&quot;C:\hitory.txt&quot;)
          While (h.Peek() &gt; -1)
              history.ListBox1.Items.Add(h.ReadLine)
          End While
          h.Close()
      Else
          'charge l'historique en mémoire
          Dim w As New IO.StreamWriter(&quot;C:\hitory.txt&quot;)
          Dim i As Integer
          For i = 0 To history.ListBox1.Items.Count - 1
              w.WriteLine(history.ListBox1.Items.Item(i))
          Next
          w.Close()
      End If
  
      If My.Computer.FileSystem.FileExists(&quot;C:\fav.txt&quot;) Then
          Dim f As New IO.StreamReader(&quot;C:\fav.txt&quot;)
          While (f.Peek() &gt; -1)
              fav.ListBox1.Items.Add(f.ReadLine)
          End While
          f.Close()
      Else
          'charge les favorit en mémoire
          Dim z As New IO.StreamWriter(&quot;C:\fav.txt&quot;)
          Dim j As Integer
          For j = 0 To fav.ListBox1.Items.Count - 1
              z.WriteLine(fav.ListBox1.Items.Item(j))
          Next
          z.Close()
      End If
      textBox1.Items.AddRange(IO.File.ReadAllLines(&quot;C:\hitory.txt&quot;))
  </code></pre>