Skip to content

[REGRESSION]: QuerySelectorAllAsync causes InvalidCastException #2830

@JustusGreiberORGADATA

Description

@JustusGreiberORGADATA

Context:

  • GOOD Playwright Version: 1.40.0
  • BAD Playwright Version: 1.41.0
  • Operating System: Windows
  • Extra: <TargetFramework>net6.0</TargetFramework>

Code Snippet

Project at https://github.com/JustusGreiberORGADATA/playwright-reproduction

using System.Threading.Tasks;
using Microsoft.Playwright;

using (var playwright = await Playwright.CreateAsync())
await using (var browser = await playwright.Chromium.LaunchAsync())
await using (var context = await browser.NewContextAsync()) {
        var page = await context.NewPageAsync();
        await page.GotoAsync("https://www.theverge.com");
        Console.WriteLine((await page.QuerySelectorAllAsync(".flex")).Count);
}

Prints stacktrace

Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Microsoft.Playwright.Transport.Converters.ChannelToGuidConverter' to type 'System.Text.Json.Serialization.JsonConverter`1[Microsoft.Playwright.Core.ElementHandle]'.
   at System.Text.Json.Serialization.JsonCollectionConverter`2.GetElementConverter(JsonTypeInfo elementTypeInfo)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadUsingMetadata[TValue](JsonElement element, JsonTypeInfo jsonTypeInfo)
   at Microsoft.Playwright.Helpers.JsonExtensions.ToObject[T](JsonElement element, JsonSerializerOptions options) in /_/src/Playwright/Helpers/JsonExtensions.cs:line 52
   at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](ChannelOwner object, String method, Dictionary`2 dictionary, Boolean keepNulls) in /_/src/Playwright/Transport/Connection.cs:line 222
   at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal)
   at Microsoft.Playwright.Core.Frame.QuerySelectorAllAsync(String selector) in /_/src/Playwright/Core/Frame.cs:line 645
   at Program.<Main>$(String[] args) in D:\repos\playwright-reproduction\Program.cs:line 9
   at Program.<Main>$(String[] args) in D:\repos\playwright-reproduction\Program.cs:line 10
   at Program.<Main>$(String[] args) in D:\repos\playwright-reproduction\Program.cs:line 10
   at Program.<Main>(String[] args)

Describe the bug

This for some reason only happens if my TargetFramework is net6.0. On .net7.0 and .net8.0 everything works fine.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions