Error while opening document from bytes 'bad allocation'

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

处理大型 PDF 文档对某些企业至关重要。

使用 IronPDF 加载现有 PDF 文件时,IronPDF 分配一部分内存来存储已加载的 PDF。 在32位上运行的应用程序每个进程的内存限制为2 GB。 加载大于 500 MB 的 PDF 文件可能会超过此限制,导致 'bad allocation' 异常。

异常信息:

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

解决方案

要解决此问题,请将应用程序设置为在64位上运行。 这允许应用程序访问更大的内存空间,避免 'bad allocation' 错误。 请按照以下步骤配置您的 Visual Studio 项目以定位 64 位平台:

// 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

通过将平台目标设置为 x64,应用程序可以利用 64 位系统的扩展内存容量,从而防止与大型 PDF 文件相关的内存分配问题。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 16,154,058 | 版本: 2025.11 刚刚发布