![](/img/trans.png)
[英]Puppeteer-sharp: page is crashed from browser.NewPageAsync()
[英]Puppeteer-Sharp library did not worked and not created page in web service(wcf) project
我有一些C#Web服務(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,版本= 0.0.0.0,區域性=中性,PublicKeyToken = cc7b13ffcd2ddd51”或其依賴項之一。
.NET 4.7中添加了System.ValueTuple
。 將您的項目升級到4.7最為簡單。
如果不能,但是您的項目的目標是4.5+但低於4.7,則可以安裝System.ValueTuple NuGet軟件包。 如果在那里遇到任何麻煩,請參見此答案 。
我通過這些步驟解決了問題。 評估所有解決方案。
1-)我將.NET Framework 4.7升級為目標版本。
2-)我將這段代碼(屬性組)添加到項目的.csproj文件中
<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>
3-)然后將這段代碼添加到項目的應用程序或Web配置文件中。
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> </dependentAssembly> </assemblyBinding> </runtime>
4-)然后建立了項目,它開始工作了。
PS。 為了安裝和使用PuppeteerSharp,框架版本至少為4.6.1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.