-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dotnet] Add trimming attributes, address some AOT warnings #14637
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
}; | ||
|
||
/// <summary>Workaround for trimming.</summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the kind of workaround necessary when using a Type
as a generic argument that requires trimming annotations. Hope this is acceptable.
TEnum[] values = Enum.GetValues<TEnum>(); | ||
#else | ||
Array values = Enum.GetValues(type); | ||
#endif | ||
foreach (var value in values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
here is actually TEnum
in .NET, but object
in .NET Standard. All use of value
is either cast or are ToString()
-ed, so there's no runtime difference.
I will start to review after basic #14574 is merged. I thought that CDP requires deeper knowledge, so on hold for now. |
@nvborisenko Thanks! It looks like a lot of the work you're doing could be addressed if It doesn't have much support because this kind of conversion isn't roundtrippable. Maybe Selenium can make the case for this functionality there? |
No, Source Generation in Json is very good. The problem I am trying to resolve is that many many years ago wire objects were serialized as You referenced to the issue, which is in open state... |
@nvborisenko Yeah the But, that would involve a lot of legwork. I would love to contribute any PRs if that's the direction this project wants to go down. |
I am in communication with https://github.com/appium/appium team, they are testing #14574 We should migrate "classic" before moving further. |
Unfortunately it is big boom breaking change :( |
// If we're shadow copying, get the directory from the codebase instead | ||
if (AppDomain.CurrentDomain.ShadowCopyFiles) | ||
{ | ||
Uri uri = new Uri(executingAssembly.CodeBase); | ||
currentDirectory = Path.GetDirectoryName(uri.LocalPath); | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assembly.CodeBase
always throws an exception in modern .NET.
Luckily, AppDomain.ShadowCopyFiles
always returns false
in modern .NET; the concept of shadow copying does not exist anymore.
These changes fix warnings and simplify the code path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot use preprocessor directives. netstandard2.0
can be consumed by .net6
. I am not sure what alternatives I can propose, probably just to suppress the warning (only if we cannot find out better way).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it is even not warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no problem with including this in .NET standard to be consumed by .NET 6. AppDomain.CurrentDomain.ShadowCopyFiles
will just return false
like before.
This is just addressing the warning when compiling against .NET 8, produced by Assembly.CodeBase
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if modern .NET recognized at compile time, that anything hidden behind AppDomain.CurrentDomain.ShadowCopyFiles
is dead code. But that's unfortunately not the case, so this directive is necessary to address warnings
I removed the devtools changes from this PR. This PR doesn't need to handle the AOT compat for that scenario, such changes can come after (maybe paired with some generator changes, who knows). |
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
This improves the story for trimming/AOT using Selenium, specifically addressing non-JSON related warnings.
Motivation and Context
In furtherance of #14480
Types of changes
Checklist
PR Type
Enhancement, Other
Description
DevToolsDomains
class to improve AOT compatibility by introducing aDomainType
struct and usingDynamicallyAccessedMembers
attributes.JsonEnumMemberConverter
class by adding attributes for public fields and updating enum value retrieval for .NET 5.0 or greater.TrimmingAttributes.cs
with custom attributes to support trimming and AOT compatibility, including conditional compilation for different .NET versions.WebDriver.csproj
file to include a conditional AOT compatibility property for future .NET versions.Changes walkthrough 📝
DevToolsDomains.cs
Enhance DevToolsDomains for AOT compatibility
dotnet/src/webdriver/DevTools/DevToolsDomains.cs
DomainType
struct to handle trimming.DynamicallyAccessedMembers
attribute for public constructors.DomainType
instead ofType
.JsonEnumMemberConverter.cs
Improve JsonEnumMemberConverter for AOT compatibility
dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs
DynamicallyAccessedMembers
attribute for public fields.TrimmingAttributes.cs
Add custom trimming attributes for AOT support
dotnet/src/webdriver/Internal/TrimmingAttributes.cs
DynamicallyAccessedMembers
and related attributes.WebDriver.csproj
Update project file for potential AOT compatibility
dotnet/src/webdriver/WebDriver.csproj