修复macOS ARM上IronPdfEngine Docker连接失败

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

在macOS ARM设备(Apple Silicon)上通过Docker连接.NET应用程序到IronPdfEngine时,应用程序会引发:

Unhandled exception. System.IO.FileNotFoundException: Error loading native library.
Not found in any of the possible locations

IronPdfConnectionType.Docker 使用较旧的gRPC实现,不支持ARM架构。 在macOS ARM (Apple Silicon)上,即使强制Docker镜像以--platform linux/amd64方式运行,.NET客户端也无法加载所需的本地gRPC二进制文件。 Windows和Linux x64平台不受影响。

解决方案

在连接配置中,用IronPdfConnectionType.DockerRemoteServer 使用与ARM兼容的较新的gRPC实现:

using IronPdf;

var config = new IronPdfConnectionConfiguration
{
    ConnectionType = IronPdfConnectionType.RemoteServer,
    Host = "http://127.0.0.1",
    Port = 33350
};

IronPdf.Installation.ConnectToIronPdfHost(config);

IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY");

var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Hello from IronPdfEngine</h1>");
pdf.SaveAs("output.pdf");
using IronPdf;

var config = new IronPdfConnectionConfiguration
{
    ConnectionType = IronPdfConnectionType.RemoteServer,
    Host = "http://127.0.0.1",
    Port = 33350
};

IronPdf.Installation.ConnectToIronPdfHost(config);

IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY");

var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Hello from IronPdfEngine</h1>");
pdf.SaveAs("output.pdf");
Imports IronPdf

Dim config As New IronPdfConnectionConfiguration With {
    .ConnectionType = IronPdfConnectionType.RemoteServer,
    .Host = "http://127.0.0.1",
    .Port = 33350
}

IronPdf.Installation.ConnectToIronPdfHost(config)

IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY")

Dim renderer As New ChromePdfRenderer()
Dim pdf = Await renderer.RenderHtmlAsPdfAsync("<h1>Hello from IronPdfEngine</h1>")
pdf.SaveAs("output.pdf")
$vbLabelText   $csharpLabel

要求:

  • 在调用ConnectToIronPdfHost之前,IronPdfEngine Docker容器必须在指定的主机和端口上运行并可访问。
  • 使用https://; 如果没有有效的SSL证书,使用https://会在gRPC通道中导致帧损坏错误。

另请参见:Docker中Vulkan/ANGLE初始化错误的故障排除修复Azure容器中的gRPC连接错误

Curtis Chau
技术作家

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

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

准备开始了吗?
Nuget 下载 20,088,359 | 版本: 2026.7 刚刚发布
Still Scrolling Icon

还在滚动吗?

想快速获得证据? PM > Install-Package IronPdf
运行示例看着你的HTML代码变成PDF文件。