Skip to content
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

NullReferenceException in NewContextAsync #2071

Closed
SimonCropp opened this issue Mar 17, 2022 · 10 comments
Closed

NullReferenceException in NewContextAsync #2071

SimonCropp opened this issue Mar 17, 2022 · 10 comments

Comments

@SimonCropp
Copy link
Contributor

System.NullReferenceException : Object reference not set to an instance of an object.
   at Microsoft.Playwright.Core.Browser.NewContextAsync(BrowserNewContextOptions options) in /_/src/Playwright/Core/Browser.cs:line 121
   at Microsoft.Playwright.Core.Browser.NewPageAsync(BrowserNewPageOptions options) in /_/src/Playwright/Core/Browser.cs:line 164
  • net6
  • <PackageReference Include="Microsoft.Playwright" Version="1.20.1" />
using System.Threading.Tasks;
using Microsoft.Playwright;

class Program
{
    public static async Task Main()
    {
        using var playwright = await Playwright.CreateAsync();
        await using var browser = await playwright.Chromium.LaunchAsync();
        var page = await browser.NewPageAsync();
        // ...
    }
}

offending line

https://github.com/microsoft/playwright-dotnet/blob/main/src/Playwright/Core/Browser.cs#L121

 ((Tracing)context.Tracing).LocalUtils = LocalUtils;
@SimonCropp
Copy link
Contributor Author

seems BrowserContextInitializer.Tracing is deserialized as null

image

@mxschmitt
Copy link
Member

Is this maybe the same as #2069? Does it also happen on new projects?

@SimonCropp
Copy link
Contributor Author

its weird. i cant repro in a new app. but i re-cloned my code and it still happens. this is the codebase that it fails in https://github.com/VerifyTests/Verify.HeadlessBrowsers

@slang25
Copy link
Contributor

slang25 commented Mar 17, 2022

This threw me for a while, my issue was I needed to do a rebuild. It happens due to a mismatch of the JavaScript version and package version.
There's a few things that might help:

  • a better error when this occurs. The current NRE doesn't explain what's wrong. There should be a correctness version check ahead of it here. Or at least an explicit null check with a message suggesting their might be a version mismatch (feels a little hacky)
  • some msbuild smarts to not require a rebuild. Maybe the version number should go into the path so there's no chance of a stale dependency. Maybe a cache file in the obj folder that is used to record the version and force an update when needed?

I'd suggest a better null check on the tracing property (as consistency cannot be assumed due to too many moving parts), and the version number in the npm content that is copied to the bin folder.

@slang25
Copy link
Contributor

slang25 commented Mar 17, 2022

To be clear, it's the "preserve newest" copy behaviour of these files that results in a version mismatch:

<_PlaywrightCopyItems Include="$(MSBuildThisFileDirectory)..\.playwright\package\**">
<PlaywrightFolder>package\</PlaywrightFolder>
</_PlaywrightCopyItems>

for some reason it will not overwrite the existing package, which then leads to this exception.

@slang25
Copy link
Contributor

slang25 commented Mar 17, 2022

I think we are hitting this known issue with the "fast update-to-date checker" dotnet/project-system#4665

@mxschmitt
Copy link
Member

mxschmitt commented Mar 17, 2022

Folding into #2069 Thank you folks for the input! We'll fix it in the driver side and provide recent modification dates with the next release.

@Joe118
Copy link

Joe118 commented Jun 12, 2022

Still seeing this problem with NewContextAsync. I posted the details on #2069

@mxschmitt
Copy link
Member

Still seeing this problem with NewContextAsync. I posted the details on #2069

Please file a new issue.

@Joe118
Copy link

Joe118 commented Jun 13, 2022

Done, #2175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants