【问题标题】:Puppeteer-Sharp library did not worked and not created page in web service(wcf) projectPuppeteer-Sharp 库没有工作,也没有在 Web 服务(wcf)项目中创建页面
【发布时间】:2020-01-14 12:43:00
【问题描述】:

我有一些 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, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51”或其依赖项之一。

【问题讨论】:

    标签: c# .net web-services puppeteer puppeteer-sharp


    【解决方案1】:

    System.ValueTuple 在 .NET 4.7 中添加。将您的项目升级到 4.7 是最简单的。

    如果您不能,但您的项目的目标版本是 4.5+ 但低于 4.7,那么您可以安装 System.ValueTuple NuGet 包。如果您在那里遇到任何问题,请参阅this answer

    【讨论】:

    • 我将我的 webservice 项目的目标版本从 4.5.2 升级到 4.6.1 我还从 Nuget 安装了 System.ValueTuple。但是我从您的链接中不了解如何以及在何处添加代码。我添加了类似的链接代码,但发布到服务器后,不起作用。
    • 你能把你的项目升级到4.7吗?这是解决此问题的简单方法。
    • 将项目更新为 4.7 作为目标版本,但结果相同。
    • 还在抱怨System.ValueTuple
    【解决方案2】:

    我通过这些步骤解决了问题。评估所有解决方案。

    1-) 我将 .NET Framework 4.7 升级为目标版本。

    2-) 我将这段代码(属性组)添加到项目的 .csproj 文件中

    <PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>

    3-) 然后将这段代码添加到项目的应用程序或网络配置文件中。

    <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。

    【讨论】:

      猜你喜欢
      • 2012-07-11
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多