IRONSOFTWAREHOME

Intermittent AccessViolationException During Form Processing

Curtis Chau
Curtis Chau
Updated: August 21, 2026

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)
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 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
VB .NET

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
Technical Writer

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 21,228,841Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999