修复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.Docker。 RemoteServer 使用与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通道中导致帧损坏错误。
准备开始了吗?
Nuget 下载 20,088,359 | 版本: 2026.7 刚刚发布

