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 文件可能會超過此限制,導致'壞分配'異常。

異常消息:

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

解決方案

為了解決此問題,請設置應用程序在64 位上運行。 這允許應用程序訪問更大的內存空間,避免'壞分配'錯誤。 按照這些步驟將您的 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 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 16,154,058 | 版本: 2025.11 剛剛發布