Intermittent AccessViolationException During Form Processing
IronPDF can throw an intermittent native AccessViolationException (code c0000005) while processing PDF forms. The crash does not reproduce reliably, even on the same input file.
System.AccessViolationException (c0000005)
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 in flight, the native layer accesses memory that has already been freed, which produces the access violation. It surfaces most often when accessing PdfDocument.Form and during PdfDocument.Flatten and PdfDocument.Merge.
You may also see repeated bad conversion while widening narrow string warnings and warnings about removing form-field annotations during flattening. These are separate and benign. 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. Keep the PdfDocument alive for the full duration of form processing
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
The GC.KeepAlive(doc) call stops the runtime from collecting the document while native form operations are still running.
2. Remove manual GC.Collect() calls during processing
Drop any explicit GC.Collect() calls made 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.

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.