title: itextsharp the process cannot access the file
body: <p>I need some serious help. I'm in a jam and I would appreciate any help I can get. I searched the web for hours, and I'm coming up empty handed. I made a project that does recursion in a directory and converts all images to PDF. I'm using itextsharp and pdfsharp (they seem to not work well without one another). Anyway, the project was working perfect until visual studio was complaining about assemblies which I learned from the last time that when VS fixes things it breaks them. So, I ignored it. While on the phone with the [insert colorful words here] beta testing it he confused the hell out of me and I ended up clicking on the warning that VS was throwing. When I clicked it I started to get the following errors: 1) When converting a pdf file it only converts the first 15 bytes of any file in the directory. 2) When the PDF is already present it errors with the exception in the caption. Here is the code I'm working with that was working prefectly: </p>
  
  <p>WebException was unhandled (<strong>this is not a WEB APP</strong>)
  The process cannot access the file 'filepath\andname.pdf' because it is being used by another process.</p>
  
  <p>Before this, when I had the original code loaded in the app.config section of my application I would get this error: </p>
  
  <p>FileLoadException was unhandled
  Could not load file or assembly 'itextsharp, Version=5.3.2.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)</p>
  
  <p>Can anyone PLEASE PLEASE PLEASE help me before I strangle this guy and sell his liver on the black market? This is frustrating as hell. I would greatly appreciate it. </p>
  
  <p>./x86</p>
  
  <p><strong>In order of the app.config file that bombs on access as in the caption, and only adds 15 bytes to the application:</strong> </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
        &lt;section name="TAMI.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
    &lt;system.diagnostics&gt;
    &lt;/system.diagnostics&gt;
    &lt;userSettings&gt;
      &lt;TAMI.My.MySettings&gt;
        &lt;setting name="scanner" serializeAs="String"&gt;
          &lt;value /&gt;
        &lt;/setting&gt;
        &lt;setting name="authenticated_user" serializeAs="String"&gt;
          &lt;value /&gt;
        &lt;/setting&gt;
      &lt;/TAMI.My.MySettings&gt;
    &lt;/userSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>THE ASSEMBLIES THAT ERROR WITH THE INCORRECT VERSION</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
        &lt;section name="TAMI.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
    &lt;system.diagnostics&gt;
      &lt;sources&gt;
        &lt;!-- This section defines the logging configuration for My.Application.Log --&gt;
        &lt;source name="DefaultSource" switchName="DefaultSwitch"&gt;
          &lt;listeners&gt;
            &lt;add name="FileLog"/&gt;
            &lt;!-- Uncomment the below section to write to the Application Event Log --&gt;
            &lt;!--&lt;add name="EventLog"/&gt;--&gt;
          &lt;/listeners&gt;
        &lt;/source&gt;
      &lt;/sources&gt;
      &lt;switches&gt;
        &lt;add name="DefaultSwitch" value="Information"/&gt;
      &lt;/switches&gt;
      &lt;sharedListeners&gt;
        &lt;add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/&gt;
        &lt;!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --&gt;
        &lt;!--&lt;add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/&gt; --&gt;
      &lt;/sharedListeners&gt;
    &lt;/system.diagnostics&gt;
    &lt;userSettings&gt;
      &lt;TAMI.My.MySettings&gt;
        &lt;setting name="scanner" serializeAs="String"&gt;
          &lt;value/&gt;
        &lt;/setting&gt;
        &lt;setting name="authenticated_user" serializeAs="String"&gt;
          &lt;value/&gt;
        &lt;/setting&gt;
      &lt;/TAMI.My.MySettings&gt;
    &lt;/userSettings&gt;
      &lt;runtime&gt;
          &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
              &lt;dependentAssembly&gt;
                  &lt;assemblyIdentity name="itextsharp" publicKeyToken="8354AE6D2174DDCA" culture="neutral"/&gt;
                  &lt;bindingRedirect oldVersion="0.0.0.0-5.3.2.0" newVersion="5.3.2.0"/&gt;
              &lt;/dependentAssembly&gt;
          &lt;/assemblyBinding&gt;
      &lt;/runtime&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>THE CODE IVE BEEN USING ALL ALONG</strong></p>
  
  <pre><code>        For b As Integer = 0 To lboxconv.Items.Count - 1
              Application.DoEvents()
              Dim extension = Microsoft.VisualBasic.Right(b, 3)
              Dim doc As New Document()
              Dim File_Type As String
              File_Type = Replace(lboxconv.Items(b), ".png", ".pdf", vbTextCompare)
              Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(File_Type, FileMode.Create))
              doc.Open()
              Dim imgpath As String = lboxconv.Items(b)
              Dim png As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imgpath)
              png.ScaleToFit("500", "500")
              png.Alignment = Element.ALIGN_CENTER
              doc.Add(png)
              doc.Close()
          Next
  </code></pre>
  
  <p>someone please help! I'm desperate and running out time and answers. </p>