Skip to content

[dotnet] [bidi] AOT safe json converter for Input.Origin class#16962

Merged
nvborisenko merged 3 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-aot-suppress
Jan 20, 2026
Merged

[dotnet] [bidi] AOT safe json converter for Input.Origin class#16962
nvborisenko merged 3 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-aot-suppress

Conversation

@nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Jan 20, 2026

User description

💥 What does this PR do?

Resolves aot trimming warning.

🔄 Types of changes

  • Cleanup (formatting, renaming)

PR Type

Enhancement


Description

  • Removes suppression attributes and implements AOT-safe serialization

  • Uses explicit type info for ISharedReference serialization

  • Eliminates IL2026 and IL3050 trimming warnings properly


Diagram Walkthrough

flowchart LR
  A["InputOriginConverter"] -->|"Remove suppression attributes"| B["Clean code"]
  A -->|"Use GetTypeInfo for serialization"| C["AOT-safe implementation"]
  C -->|"Explicit type resolution"| D["No trimming warnings"]
Loading

File Walkthrough

Relevant files
Enhancement
InputOriginConverter.cs
AOT-safe JSON serialization for Origin class                         

dotnet/src/webdriver/BiDi/Json/Converters/InputOriginConverter.cs

  • Removed System.Diagnostics.CodeAnalysis using statement
  • Removed two UnconditionalSuppressMessage attributes for IL2026 and
    IL3050 warnings
  • Replaced generic JsonSerializer.Serialize call with explicit type info
    using options.GetTypeInfo()
  • This approach properly handles AOT compilation without suppressing
    warnings
+4/-4     

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Jan 20, 2026

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No audit logging scope: The diff only changes JSON serialization behavior and does not show whether any critical
actions that require audit trails are logged elsewhere in the system.

Referred Code
public override void Write(Utf8JsonWriter writer, Origin value, JsonSerializerOptions options)
{
    if (value is ViewportOrigin)
    {
        writer.WriteStringValue("viewport");
    }
    else if (value is PointerOrigin)
    {
        writer.WriteStringValue("pointer");
    }
    else if (value is ElementOrigin element)
    {
        writer.WriteStartObject();
        writer.WriteString("type", "element");
        writer.WritePropertyName("element");

        var sharedReferenceTypeInfo = options.GetTypeInfo<Script.ISharedReference>();
        JsonSerializer.Serialize(writer, element.Element, sharedReferenceTypeInfo);

        writer.WriteEndObject();
    }


 ... (clipped 1 lines)

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Jan 20, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Use TryGetTypeInfo for safer serialization

Replace GetTypeInfo with TryGetTypeInfo to prevent potential
InvalidOperationException and provide a fallback for serialization.

dotnet/src/webdriver/BiDi/Json/Converters/InputOriginConverter.cs [50-51]

-var sharedReferenceTypeInfo = options.GetTypeInfo<Script.ISharedReference>();
-JsonSerializer.Serialize(writer, element.Element, sharedReferenceTypeInfo);
+if (options.TryGetTypeInfo<Script.ISharedReference>(out var sharedReferenceTypeInfo))
+{
+    JsonSerializer.Serialize(writer, element.Element, sharedReferenceTypeInfo);
+}
+else
+{
+    // Fallback to the reflection-based serializer if the AOT-safe one is not available.
+    // This might be needed for contexts where the options are not configured for source generation.
+    JsonSerializer.Serialize(writer, (object)element.Element, options);
+}
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out that GetTypeInfo<T>() can throw an exception if the JsonSerializerOptions instance is locked. Using TryGetTypeInfo is a more robust pattern, and providing a fallback to the reflection-based serializer is a good defensive practice.

Medium
  • Update

@nvborisenko nvborisenko merged commit 2e04ed4 into SeleniumHQ:trunk Jan 20, 2026
14 checks passed
@nvborisenko nvborisenko deleted the bidi-aot-suppress branch January 20, 2026 18:29
This was referenced Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants