我有一些用于 C# 网络服务 (WCF) 的代码并使用 puppeteer-sharp 库。首先,应创建页面,相关方法位于名为 SayfaOlustur() 的下方。但是我遇到了 System.IO.FileLoadException 异常行 LaunchOptions。
此代码在我的本地机器和 TestProject(在 TestClass 中使用了 TestMethods)上运行,但在发布整个代码页后没有创建并抛出 System.IO.FileLoadException 和 System.Value 异常。
System.Value.dll 包含在项目引用和 bin 文件夹中。
public static async Task<Page> SayfaOlusturAsync()
{
Browser browser = null;
try
{
var filePath = ConfigurationManager.AppSettings["PuppeterSharpBrowserFetcherLocalChromium"].ToString();
var browserFetcher = new BrowserFetcher(new BrowserFetcherOptions
{
Path = string.IsNullOrEmpty(filePath) ? @"C:\PuppeteerSharpLocalChromium" : filePath
});
await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);
var options = new LaunchOptions
{
Headless = true,
ExecutablePath = @"C:\PuppeteerSharpLocalChromium\Win64-674921\chrome-win\chrome.exe"
};
browser = await Puppeteer.LaunchAsync(options);
}
catch (Exception ex)
{
HelperUtils.CmsLogger.Error(ex, "SayfaOlusturAsync");
}
return await browser.NewPageAsync();
}
预期结果是用 Chronumium 创建了一个页面
异常详情
System.IO.FileLoadException:'无法加载文件或程序集“System.ValueTuple,Version=0.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”或其依赖项之一。
最佳答案
System.ValueTuple
在 .NET 4.7 中添加。将您的项目升级到 4.7 是最简单的。
如果不能,但您的项目的目标版本是 4.5+ 但低于 4.7,那么您可以安装 System.ValueTuple NuGet 包。如果您在那里遇到任何问题,请参阅 this answer .
关于c# - Puppeteer-Sharp 库没有工作,也没有在 web 服务 (wcf) 项目中创建页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57910073/