Intermittent AccessViolationException During Form Processing

Curtis Chau
Curtis Chau
Updated: October 29, 2026

IronPDF can throw an intermittent native AccessViolationException (code c0000005) during PDF form processing. It does not reproduce reliably, even on the same input file.

System.AccessViolationException (0xc0000005)
bad conversion while widening narrow string
Text

The crash comes from the interaction between native form-field handles and managed object lifetime. If the PdfDocument is garbage-collected or disposed while native form operations are still running, the native layer accesses memory that has already been freed, producing the access violation. 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 plus warnings about removing form-field annotations during flattening.

The "bad conversion" warnings are a separate, benign symptom. They come from decoding internal AcroForm field strings and metadata that contain Japanese or 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.

Please note: This issue is fixed in IronPDF v2026.9.2. If you can, upgrade to that version rather than applying the workarounds below. The steps here are for users still on versions prior to v2026.9.2. Version found: 2026.5.2.

Solution

1. Keep the PdfDocument alive for the full duration of form processing

This is the recommended fix. Wrap the document in a Using block so its lifetime is explicit, then call GC.KeepAlive(doc) after the form-field loop, before the document is disposed.

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
VB

GC.KeepAlive(doc) stops the runtime from collecting the document while native form operations are still running.

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. Drop any explicit GC.Collect() calls from your PDF and form code paths.

3. Run the application as x64 only

Set the project platform target explicitly to x64, and confirm that Prefer 32-bit is disabled.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

Read More

Ready to Get Started?

NuGet Downloads 22,198,312Version:2026.11just released