Skip to content
English
  • There are no suggestions because the search field is empty.

IronPDF - Intermittent AccessViolationException During Form Processing (c0000005)

Overview

During PDF form processing, IronPDF can raise an intermittent native AccessViolationException (code c0000005) that does not reproduce reliably even on the same input file. The crash is tied to native form-field handles and object lifetime: the managed PdfDocument can be garbage-collected or disposed while native form operations are still running, leaving the native layer accessing freed memory. It surfaces most often when accessing PdfDocument.Form and during PdfDocument.Flatten and PdfDocument.Merge, and is sometimes accompanied by repeated "bad conversion while widening narrow string" warnings and warnings about removing form-field annotations during flattening. The fix is to run as x64, manage the document's lifetime explicitly, and avoid premature garbage collection.

Version Metadata

  • Version Found: 2026.5.2

  • Version Resolved: N/A

Cause

The intermittent crash is caused by the interaction between native form-field handles and managed object lifetime during form processing. If the PdfDocument is collected or disposed while native form operations are still in flight, the native code accesses memory that has already been freed, producing the access violation. The repeated "bad conversion" warnings are a separate and benign symptom — they come from decoding internal AcroForm field strings and metadata that contain Japanese/multibyte characters in this particular PDF. They do not indicate a problem with Japanese or Unicode support in general, nor with Japanese UNC file paths.

Solution

  1. Recommended: Keep the PdfDocument alive for the full duration of form processing. Wrap the document in a Using block so its lifetime is explicit, and call GC.KeepAlive(doc) after the form-field loop, before the document is disposed. This stops the runtime from collecting the document while native form operations are still running.
    Using doc As IronPdf.PdfDocument = IronPdf.PdfDocument.FromFile(tempPdfPath)

           For Each field In doc.Form

               ' Your form field processing here

           Next

           GC.KeepAlive(doc)

       End Using

     

  2. Remove manual GC.Collect() calls during PDF and form processing. Forcing collection mid-operation can trigger the exact lifetime problem that causes the crash.
  3. Run the application as x64 only. Set the project platform target explicitly to x64 and make sure Prefer 32-bit is disabled.