microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

[BUG] NewPageAsync() causes a null exception #2045

Closed Chryogenic closed 2 years ago

Chryogenic commented 2 years ago

Context:

Code Snippet

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

Describe the bug Gets an error when it hits the line var page = await browser.NewPageAsync();: System.NullReferenceException: 'Object reference not set to an instance of an object.'

This happens every time.

Add any other details about the problem here: Seems to be similar to @#1777

When I revert to 1.18.1 I no longer have this issue.

mxschmitt commented 2 years ago

Which windows version are you using?

Could you try setting the DEBUG=pw:api,pw:browser,pw:channel:response,pw:channel:command environment variable? This should give us more clue whats going wrong.

campersau commented 2 years ago

You can also try to rebuild your project (it worked for me).

I think the exception happens here: https://github.com/microsoft/playwright-dotnet/blob/98db95b3b279f8654674d7434479625bb5d8cc76/src/Playwright/Core/Browser.cs#L121

Here is the stacktrace:

   bei Microsoft.Playwright.Core.Browser.<NewContextAsync>d__33.MoveNext()
   bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   bei Microsoft.Playwright.Core.Browser.<NewPageAsync>d__34.MoveNext()
   bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   bei Program.<<Main>$>d__0.MoveNext() in Program.cs: Zeile5
Chryogenic commented 2 years ago

@campersau - A rebuild has done the trick. Thanks! @mxschmitt - Unfortunately, I am no longer able to reproduce the issue. I am using Windows 11 version 21H2 (OS Build 22000.493).