Error while opening document from bytes 'bad allocation'

This article was translated from English: Does it need improvement?
Translated
View the article in English

Processing large PDF documents can be crucial for some businesses.

When using IronPDF to load an existing PDF file, IronPDF allocates a portion of memory to store the loaded PDF. Applications running on 32-bit have a memory limit of 2 GB per process. Loading a PDF file larger than 500 MB can exceed this limitation, resulting in a 'bad allocation' exception.

Exception message:

IronPdf.Exceptions.IronPdfNativeException: 'Error while opening document from bytes: 'bad allocation'.

Solution

To solve this, please set the application to run on 64-bit. This allows the application to access a larger memory space, avoiding the 'bad allocation' error. Follow these steps to configure your Visual Studio project to target a 64-bit platform:

// Open your project in Visual Studio
// In the Solution Explorer, right-click on your project and select 'Properties'

// Navigate to the 'Build' tab

// Select 'x64' from the 'Platform target' dropdown
<PropertyGroup>
  <PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

// Save your changes and rebuild the project
// Open your project in Visual Studio
// In the Solution Explorer, right-click on your project and select 'Properties'

// Navigate to the 'Build' tab

// Select 'x64' from the 'Platform target' dropdown
<PropertyGroup>
  <PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

// Save your changes and rebuild the project
' Open your project in Visual Studio
' In the Solution Explorer, right-click on your project and select 'Properties'

' Navigate to the 'Build' tab

' Select 'x64' from the 'Platform target' dropdown
(Of PropertyGroup) (Of PlatformTarget) x64</PlatformTarget> </PropertyGroup>

' Save your changes and rebuild the project
$vbLabelText   $csharpLabel

By setting the platform target to x64, the application can utilize the expanded memory capacity of a 64-bit system, thereby preventing memory allocation issues related to large PDF files.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado