Skip to content

Commit

Permalink
[dotnet] Make Selenium Manager's AOT safety explicit (#14733)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenderMichael authored Nov 8, 2024
1 parent 5c9d683 commit fbe116c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public static class SeleniumManager
{
private static readonly ILogger _logger = Log.GetLogger(typeof(SeleniumManager));

private static readonly JsonSerializerOptions _serializerOptions = new() { PropertyNameCaseInsensitive = true, TypeInfoResolver = SeleniumManagerSerializerContext.Default };

private static readonly Lazy<string> _lazyBinaryFullPath = new(() =>
{
string? binaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH");
Expand Down Expand Up @@ -187,7 +185,7 @@ private static ResultResponse RunCommand(string fileName, string arguments)

try
{
jsonResponse = JsonSerializer.Deserialize<SeleniumManagerResponse>(output, _serializerOptions)!;
jsonResponse = JsonSerializer.Deserialize(output, SeleniumManagerSerializerContext.Default.SeleniumManagerResponse)!;
}
catch (Exception ex)
{
Expand All @@ -210,11 +208,11 @@ private static ResultResponse RunCommand(string fileName, string arguments)
}
}

internal record SeleniumManagerResponse(IReadOnlyList<LogEntryResponse> Logs, ResultResponse Result)
internal sealed record SeleniumManagerResponse(IReadOnlyList<LogEntryResponse> Logs, ResultResponse Result)
{
public record LogEntryResponse(string Level, string Message);
public sealed record LogEntryResponse(string Level, string Message);

public record ResultResponse
public sealed record ResultResponse
(
[property: JsonPropertyName("driver_path")]
string DriverPath,
Expand All @@ -224,5 +222,6 @@ string BrowserPath
}

[JsonSerializable(typeof(SeleniumManagerResponse))]
internal partial class SeleniumManagerSerializerContext : JsonSerializerContext;
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]
internal sealed partial class SeleniumManagerSerializerContext : JsonSerializerContext;
}

0 comments on commit fbe116c

Please sign in to comment.