2

I have some code for C# web service(WCF) and use puppeteer-sharp library. First of all, page should be created and related method located below named SayfaOlustur(). However I faced System.IO.FileLoadException exception line LaunchOptions.

This code worked on my local machine and TestProject(used TestMethods in TestClass) but after publishing whole code page did not created and throw System.IO.FileLoadException and System.Value exception.

System.Value.dll included in project reference and bin folder.

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();
    }

Expected result is created a page with Chronumium

Exception details

System.IO.FileLoadException: 'Could not load file or assembly "System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" or one of its dependencies.

Mert Metin
  • 373
  • 2
  • 13

2 Answers2

0

System.ValueTuple was added in .NET 4.7. Upgrading your project to 4.7 would be easiest.

If you can't, but your project is targetting a version 4.5+ but less than 4.7, then you can install the System.ValueTuple NuGet package. If you run into any trouble there, see this answer.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • I upgraded my webservice project's targetting version to 4.6.1 from 4.5.2 Also i installed System.ValueTuple from Nuget. But I do not understand from your link in terms of how and where to add the code. I add similar code of your link but after publishing to server, not worked. – Mert Metin Sep 12 '19 at 20:19
  • Can you upgrade your project to 4.7? That's the easy way to fix this. – Gabriel Luci Sep 12 '19 at 20:49
  • Updated the project to 4.7 as a targetting version but result is the same. – Mert Metin Sep 13 '19 at 07:08
  • It's still complaining about `System.ValueTuple`? – Gabriel Luci Sep 13 '19 at 10:02
0

I solved the problem with these steps. All solutions evaluated.

1-) I upgraded .NET Framework 4.7 as targeting version.

2-) I added this piece of code(property group) to project's .csproj file

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

3-) Then added this piece of code to project's app or web config file.

<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-) Then Builded the project and it worked.

PS. In order to install and use PuppeteerSharp, the framework version at least 4.6.1.

Mert Metin
  • 373
  • 2
  • 13