IRONSOFTWAREHOME

AccessViolationException During Form Processing (c0000005)

Curtis Chau
Curtis Chau
Updated: July 3, 2026

While processing PDF forms, IronPDF can throw an intermittent native AccessViolationException (code c0000005) that does not reproduce reliably, even on the same input file. It shows up most often when you access PdfDocument.Form and during PdfDocument.Flatten and PdfDocument.Merge.

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 in flight, the native layer accesses memory that has already been freed, which produces the access violation.

The repeated "bad conversion while widening narrow string" warnings, along with warnings about removing form-field annotations during flattening, are a separate and benign symptom. They come from decoding internal AcroForm field strings and metadata that contain Japanese or multibyte characters in a given PDF. They do not indicate a problem with Japanese or Unicode support in general, nor with Japanese UNC file paths.

Solution

1. Keep the Document Alive for the Full Operation

Recommended: hold the PdfDocument in scope for the entire duration of form processing. Wrap it 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

GC.KeepAlive(doc) stops the runtime from collecting the document while native form operations are still running, closing the window in which the native code can hit freed memory.

2. Remove Manual GC.Collect() Calls

Delete any GC.Collect() calls during PDF and form processing. Forcing collection mid-operation can trigger the exact lifetime problem that causes the crash.

3. Target x64 Only

Set the project platform target explicitly to x64, and make sure Prefer 32-bit is disabled. Running as x64 avoids the constraints of a 32-bit process during native form work.

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 20,389,208Version:2026.8just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required

Try IronPDF for Free

Get Set Up in 5 Minutes

C# PDF DLL

Download DLL

Download Now

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"
C# NuGet Library for PDF

Install with NuGet

                  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
Key in blue circle

Get your free 30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
  • 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 related to IronPDF Product Demo

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