You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request refactors the ResourceUtilities class to improve thread safety and code clarity by replacing manual lazy initialization with the Lazy<T> type for static properties. It also removes some unused using directives for a cleaner codebase.
Refactoring for thread safety and clarity:
Replaced manual lazy initialization of ProductVersion and PlatformFamily with Lazy<string>, ensuring thread-safe, lazy-loaded static properties. (dotnet/src/webdriver/Internal/ResourceUtilities.cs)
Code cleanup:
Removed unused System.Diagnostics and System.Globalization using directives for a cleaner file. (dotnet/src/webdriver/Internal/ResourceUtilities.cs)
🤖 AI assistance
No substantial AI assistance used
AI assisted (complete below)
Tool(s):
What was generated:
I reviewed all AI output and can explain the change
ResourceUtilities.GetPlatformString() still references the Process type in the #if NET462 branch,
but this PR removed the System.Diagnostics import, causing the net462 target to fail to compile.
The project targets net462, and the updated ResourceUtilities.cs still uses Process under `#if
NET462, but there is no System.Diagnostics` import in the file nor in global usings, so the symbol
will not resolve when compiling the net462 target.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`dotnet/src/webdriver/Internal/ResourceUtilities.cs` still uses `Process` inside the `#if NET462` code path, but the PR removed `using System.Diagnostics;`. Since the WebDriver project targets `net462`, this will cause a compile error when building that target.
### Issue Context
- `Selenium.WebDriver.csproj` multi-targets `net462;netstandard2.0;net8.0`.
- The `Process` type is not imported via `GlobalUsings.cs`.
### Fix Focus Areas
- dotnet/src/webdriver/Internal/ResourceUtilities.cs[20-23]
- dotnet/src/webdriver/Internal/ResourceUtilities.cs[51-67]
- dotnet/src/webdriver/Properties/GlobalUsings.cs[20-27]
### Suggested fix
Add `using System.Diagnostics;` back, ideally guarded to only apply when needed:
```csharp
#if NET462
using System.Diagnostics;
#endif
```
Alternatively, fully-qualify the type usages (`System.Diagnostics.Process`) inside the `#if NET462` block.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ResourceUtilities.GetPlatformString() still references the Process type in the #if NET462 branch,
but this PR removed the System.Diagnostics import, causing the net462 target to fail to compile.
The project targets net462, and the updated ResourceUtilities.cs still uses Process under `#if
NET462, but there is no System.Diagnostics` import in the file nor in global usings, so the symbol
will not resolve when compiling the net462 target.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`dotnet/src/webdriver/Internal/ResourceUtilities.cs` still uses `Process` inside the `#if NET462` code path, but the PR removed `using System.Diagnostics;`. Since the WebDriver project targets `net462`, this will cause a compile error when building that target.
### Issue Context
- `Selenium.WebDriver.csproj` multi-targets `net462;netstandard2.0;net8.0`.
- The `Process` type is not imported via `GlobalUsings.cs`.
### Fix Focus Areas
- dotnet/src/webdriver/Internal/ResourceUtilities.cs[20-23]
- dotnet/src/webdriver/Internal/ResourceUtilities.cs[51-67]
- dotnet/src/webdriver/Properties/GlobalUsings.cs[20-27]
### Suggested fix
Add `using System.Diagnostics;` back, ideally guarded to only apply when needed:
```csharp
#if NET462
using System.Diagnostics;
#endif
```
Alternatively, fully-qualify the type usages (`System.Diagnostics.Process`) inside the `#if NET462` block.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Make ResourceUtilities product/platform info lazy and thread-safe 🐞 Bug fix✨ Enhancement🕐 10-20 Minutes
Description
• Replace manual static caching with Lazy for thread-safe ProductVersion/PlatformFamily
• Simplify ProductVersion resolution from AssemblyInformationalVersionAttribute with a safe fallback
• Remove unused imports and legacy resource-stream helper from this partial file
The following are alternative approaches to this PR:
1. LazyInitializer.EnsureInitialized fields
➕ Thread-safe lazy init without allocating Lazy instances
➕ Keeps underlying storage as simple nullable fields
➖ More verbose and error-prone (ref params/nullability) than Lazy
➖ Harder to read/maintain for multiple properties
2. Eager static readonly initialization
➕ Simplest code; no Lazy overhead
➕ Initialization happens deterministically at type load
➖ Computes values even if never used
➖ Potentially undesirable if platform/version probing ever becomes more expensive
Recommendation: Lazy is a good fit here for clarity and thread-safety. However, validate NET462 compilation: this file still references System.Diagnostics.Process inside the NET462 block of GetPlatformString(), so removing using System.Diagnostics; likely breaks that target unless Process is imported elsewhere (e.g., global using) or fully qualified.
Files changed (1) +10 / -76
Bug fix (1) +10 / -76
ResourceUtilities.csRefactor product/platform info caching to Lazy<T>+10/-76
Refactor product/platform info caching to Lazy<T>
• Introduces Lazy<string> fields to compute ProductVersion and PlatformFamily exactly once in a thread-safe way. Simplifies ProductVersion derivation from assembly metadata and removes unused usings and an older resource-stream helper from this partial file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💥 What does this PR do?
This pull request refactors the
ResourceUtilitiesclass to improve thread safety and code clarity by replacing manual lazy initialization with theLazy<T>type for static properties. It also removes some unused using directives for a cleaner codebase.Refactoring for thread safety and clarity:
ProductVersionandPlatformFamilywithLazy<string>, ensuring thread-safe, lazy-loaded static properties. (dotnet/src/webdriver/Internal/ResourceUtilities.cs)Code cleanup:
System.DiagnosticsandSystem.Globalizationusing directives for a cleaner file. (dotnet/src/webdriver/Internal/ResourceUtilities.cs)🤖 AI assistance
🔄 Types of changes