Skip to content

Publish using "Produce single file" - Unhandled exception. System.ArgumentException: The path is empty. (Parameter 'path') #2073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stesee opened this issue Jan 22, 2023 · 9 comments · Fixed by #2074 or #2088

Comments

@stesee
Copy link
Contributor

stesee commented Jan 22, 2023

Description

PuppeteerSharp 9.0.0 introduced a bug that will cause to fail the parameterless ctor of BrowserFetcher when using in some published exe with "Produce single file" enabled.

Complete minimal example reproducing the issue

  • Get any example code that uses the parameterless ctor of BrowserFetcher and put it into a console application (.net6 and .net7 are known to cause the issue)
  • Publish project with option "Produce single file" enabled.
  • Run the published exe
  • Minimal repro

Expected behavior:

Running without exception, like PuppeteerSharp 8.

Actual behavior:

Unhandled exception. System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at System.IO.FileInfo..ctor(String originalPath, String fullPath, String fileName, Boolean isNormalized)
   at System.IO.FileInfo..ctor(String fileName)
   at PuppeteerSharp.BrowserFetcher.GetExecutablePath() in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\BrowserFetcher.cs:line 354
   at PuppeteerSharp.BrowserFetcher..ctor() in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\BrowserFetcher.cs:line 53
   at Program.<Main>$(String[] args) in C:\source\repos\PuppeteerSharpMinimalRepro\PuppeteerSharpMinimalRepro\Program.cs:line 5
   at Program.<Main>(String[] args)

Versions

  • Which version of PuppeteerSharp are you using? 9.0.0 and 9.0.1
  • Which .NET runtime and version are you targeting? .net6 and .net7

Additional Information - Workarround - Use overloads of the BrowserFetcher ctor.

var options = new BrowserFetcherOptions();
options.Path = Path.GetTempPath();
using var browserFetcher = new BrowserFetcher(options);
var revisionInfo = await browserFetcher.DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, ExecutablePath = revisionInfo.ExecutablePath });
await using var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com");
await page.ScreenshotAsync("google.jpg");
@amaitland
Copy link
Contributor

In .NET 5 and later versions, for bundled assemblies, the value returned is an empty string.

As per https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.location?view=net-5.0

For Publish Single File the Assembly.Location will return an empty string.

var assemblyLocation = typeof(Puppeteer).Assembly.Location;

For Single File exe there won't be a copy of PuppeteerSharp.dll on disk. The check to see if file exists might need to be reconsidered.

@stesee
Copy link
Contributor Author

stesee commented Jan 23, 2023

@amaitland You are right... maybe the behavior of PuppeteerSharp 8* can be brought back as fallback, when Assembly.Location is empty.

@kblok
Copy link
Member

kblok commented Jan 23, 2023

Yeah. We should fix this.

@kblok
Copy link
Member

kblok commented Jan 26, 2023

v9.0.2 is being cooked at the moment.

@stesee
Copy link
Contributor Author

stesee commented Jan 26, 2023

mh... would you accept a pr that automates publishing to nuget.org using github actions?

@kblok
Copy link
Member

kblok commented Jan 26, 2023

@stesee please!

@stesee
Copy link
Contributor Author

stesee commented Jan 26, 2023

It seems that "Improve DownloadFetcher executable path #2074" did not solve the issue.

Testing this using https://github.com/stesee/PuppeteerSharpMinimalRepro/blob/master/PuppeteerSharpMinimalReproTests/PuppeteerSharpMinimalReproTests.cs

resulting in

.\PuppeteerSharpMinimalRepro.exe
AppDomain.BaseDirectory: C:\PuppeteerSharpMinimalRepro\PuppeteerSharpMinimalRepro\bin\Release\net6.0\publish\
typeof(Puppeteer).Assembly.Location:
Unhandled exception. System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
   at System.Reflection.RuntimeAssembly.get_CodeBase()
   at PuppeteerSharp.BrowserFetcher.GetExecutablePath() in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\BrowserFetcher.cs:line 356
   at PuppeteerSharp.BrowserFetcher..ctor() in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\BrowserFetcher.cs:line 53
   at Program.<Main>$(String[] args) in C:\PuppeteerSharpMinimalRepro\PuppeteerSharpMinimalRepro\Program.cs:line 5
   at Program.<Main>(String[] args)

@kblok
Copy link
Member

kblok commented Jan 26, 2023

Ops. PRs are welcome :)

@kblok kblok reopened this Jan 26, 2023
@amaitland
Copy link
Contributor

See https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli#api-incompatibility for list of known APIs that are incompatible with SingleFile builds.

stesee added a commit to stesee/puppeteer-sharp that referenced this issue Feb 13, 2023
kblok pushed a commit that referenced this issue Feb 23, 2023
* Fixed #2073

* Fixed review findings

Fixed some errors caused by outdated test adapter serching for .net core 2.1

* Addressed review input

* Naming of test addressed

* Update PublishSingleFileTests.cs

* Update PublishSingleFileTests.cs

* Update BrowserFetcher.cs

---------

Co-authored-by: Seeland, Stefan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants