-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Closed
Labels
A-needs-triagingA Selenium member will evaluate this soon!A Selenium member will evaluate this soon!C-dotnet.NET Bindings.NET BindingsI-defectSomething is not working as intendedSomething is not working as intended
Description
What happened?
After creating a driver instance, we are unable to add cookies to the driver. Here is a .Net console app that repoduces the issue:
Reference nuget package: PackageReference Include="Selenium.WebDriver" Version="4.26.0"
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace SeleniumCookies
{
internal class Program
{
static void Main(string[] args)
{
List<Cookie> cookies = new List<Cookie>();
using (IWebDriver driver = new ChromeDriver())
{
// Navigate to a webpage
driver.Navigate().GoToUrl("https://www.google.com");
cookies = driver.Manage().Cookies.AllCookies.ToList();
foreach (var cookie in cookies)
{
driver.Manage().Cookies.AddCookie(cookie);
}
// Close the browser
driver.Quit();
}
}
}
}
Note: This only started happening in the Selenium 4.26.0 release. This works fine in the Selenium 4.25.0 release.
How can we reproduce the issue?
You can reproduce the issue by trying to add a cookie to a driver. See the 'What happened' section for a code snippet.Relevant log output
Here is the error thrown:
System.NotSupportedException
HResult=0x80131515
Message=JsonTypeInfo metadata for type 'OpenQA.Selenium.Internal.ReturnedCookie' was not provided by TypeInfoResolver of type 'OpenQA.Selenium.CommandJsonSerializerContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically. The unsupported member type is located on type 'System.Object'. Path: $.
Source=System.Text.Json
StackTrace:
at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex)
at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at OpenQA.Selenium.Command.get_ParametersAsJsonString()
at OpenQA.Selenium.Remote.HttpCommandExecutor.HttpRequestInfo..ctor(Uri serverUri, Command commandToExecute, HttpCommandInfo commandInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.<ExecuteAsync>d__34.MoveNext()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.<ExecuteAsync>d__10.MoveNext()
at OpenQA.Selenium.WebDriver.<ExecuteAsync>d__63.MoveNext()
at OpenQA.Selenium.WebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.CookieJar.AddCookie(Cookie cookie)
at SeleniumCookies.Program.Main(String[] args) in C:\Users\Jeron.Kleinfehn\source\repos\SeleniumCookies\SeleniumCookies\Program.cs:line 30
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
NotSupportedException: JsonTypeInfo metadata for type 'OpenQA.Selenium.Internal.ReturnedCookie' was not provided by TypeInfoResolver of type 'OpenQA.Selenium.CommandJsonSerializerContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.Operating System
Windows 11
Selenium version
SeleniumVersion=Selenium 4.26.0 | Programming language=.Net/C#
What are the browser(s) and version(s) where you see this issue?
Chrome 130
What are the browser driver(s) and version(s) where you see this issue?
Chrome 130 - Latest ChromeDriver in Selenium 4.26.0 package
Are you using Selenium Grid?
No
Metadata
Metadata
Assignees
Labels
A-needs-triagingA Selenium member will evaluate this soon!A Selenium member will evaluate this soon!C-dotnet.NET Bindings.NET BindingsI-defectSomething is not working as intendedSomething is not working as intended