我有一个Azure函数,我将HTML转换为PDF,然后下载结果。
昨天我将函数更新到版本4和。net 6,我也看到BrowserFetcher.DefaultRevision
已经过时,我用推荐的BrowserFetcher.DefaultChromiumRevision
取代了它,该函数在发布后不再工作。
我也在当地试过,但都很好。我收到的错误是Invalid URI: The hostname could not be parsed.
,我怀疑是木偶师。
这是我的Startup
函数代码:
public override void Configure(IFunctionsHostBuilder builder)
{
var bfOptions = new BrowserFetcherOptions();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
bfOptions.Path = Path.GetFullPath("mounted");
}
var bf = new BrowserFetcher(bfOptions);
try
{
bf.DownloadAsync(BrowserFetcher.DefaultChromiumRevision).Wait();
}
catch (Exception)
{
string zipPath = Path.Combine(bf.DownloadsFolder, $"download-{bf.Platform}-{BrowserFetcher.DefaultChromiumRevision}.zip");
string folderPath = Path.Combine(bf.DownloadsFolder, $"{bf.Platform}-{BrowserFetcher.DefaultChromiumRevision}");
using (var process = new Process())
{
process.StartInfo.FileName = "unzip";
process.StartInfo.Arguments = $""{zipPath}" -d "{folderPath}"";
process.Start();
process.WaitForExit();
}
new FileInfo(zipPath).Delete();
}
builder.Services.AddHttpClient();
builder.Services.AddSingleton<IPdfPrinterService>((s) =>
{
return new ChromiumPdfPrinterService(bf.GetExecutablePath(BrowserFetcher.DefaultChromiumRevision));
});
}
还有人遇到过这个问题吗?
我发现了这个问题。这是由RazorLight升级到稳定版本2.0.0引起的。
回滚到2.0.0-rc版本。
这是GitHub的问题:https://github.com/toddams/RazorLight/issues/481