Skip to content
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

[🚀 Feature]: [dotnet] Road to be AOT friendly #14480

Open
3 of 6 tasks
nvborisenko opened this issue Sep 9, 2024 · 26 comments
Open
3 of 6 tasks

[🚀 Feature]: [dotnet] Road to be AOT friendly #14480

nvborisenko opened this issue Sep 9, 2024 · 26 comments

Comments

@nvborisenko
Copy link
Member

nvborisenko commented Sep 9, 2024

Feature and motivation

Any consumer of Selenium library in .NET cannot use it within publishing his application as Native AOT Deployment.

The detailed affected parts are coming...

Selenium Managerv4.26

W3C WebDriverv4.26

W3C BiDi

  • ...

CDP

  • Generate JsonSerializerContext for all DTO models
  • ...

Usage example

Create console app, publish as native AOT, it fails at runtime.

Copy link

github-actions bot commented Sep 9, 2024

@nvborisenko, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@nvborisenko
Copy link
Member Author

Blocked by bazel-contrib/rules_dotnet#443

@RenderMichael
Copy link
Contributor

I’m interested in this feature for running Selenium. Often times, the roads to AOT compatibility leads to improvements across the board, even for non-AOT scenarios.

@NCLnclNCL
Copy link

Blocked by bazelbuild/rules_dotnet#443

when it will be fixed

@nvborisenko
Copy link
Member Author

Blocked by bazel-contrib/rules_dotnet#443

Fixed, waiting release soon.

Often times, the roads to AOT compatibility leads to improvements across the board, even for non-AOT scenarios.

Who knows potential issues... , I cannot prepare decomposed tasks to archive the goal. Our mission here is to adopt existing codebase to be ready for AOT.

The technical enabler is resolved, so the list of impacted areas will be be growing so fast soon.

@nvborisenko
Copy link
Member Author

@RenderMichael are you able to test the preview version of Selenium which seems is compatible with AOT (excepting CDP)? Your input would be valuable. I can share nuget package file here (built locally).

@RenderMichael
Copy link
Contributor

@nvborisenko I would be happy to test out the AOT compatibility of Selenium :)

@nvborisenko
Copy link
Member Author

Selenium.WebDriver.4.26.0-nightly202409202352.zip

@RenderMichael This is zip, which contains nupkg inside. I built it locally, and hoping you know what to do with it.

@nvborisenko
Copy link
Member Author

@RenderMichael @NCLnclNCL please don't forget to share results. Thanks guys.

@RenderMichael
Copy link
Contributor

RenderMichael commented Oct 20, 2024

@nvborisenko Unfortunately the app crashed as soon as I tried running the native .exe file:

image

I can't give more detailed feedback without building the library locally. Are there any instructions I can follow to build the .NET bindings locally? A while back I tried to do so following this guide but ran into some blockers (I no longer remember what they were).

Exit: it was my error

@RenderMichael
Copy link
Contributor

This was my program for the above. Completely ideomatic, no obscure Selenium features or anything.

using OpenQA.Selenium.Firefox;

var options = new FirefoxOptions
{
    AcceptInsecureCertificates = true,
};

using (var driver = new FirefoxDriver(options))
{
    await driver.Navigate().GoToUrlAsync("https://www.google.com");

    string url = driver.Url;
    if (!url.Contains("google"))
    {
        throw new Exception("URL does not contain google: " + url);
    }
}

Console.ReadKey();

@nvborisenko
Copy link
Member Author

@RenderMichael did you use nupkg file I provided above? Or you just referenced to dll from that package?

@NCLnclNCL
Copy link

@RenderMichael @NCLnclNCL please don't forget to share results. Thanks guys.

it works very well, the file size is also very light

@nvborisenko
Copy link
Member Author

@NCLnclNCL did you try it on your "production" project? Or just on simple "Hello World"?

@RenderMichael
Copy link
Contributor

@nvborisenko Ah that was from a fluke antivirus mis-configuration on my part, I didn't release there was supposed to be a selenium-manager folder alongside the program, and the TypeInitalizationException in my stack trace threw me off. Sorry!

The Hello World is working great for me now, I will try with a more serious program. Thanks!

@RenderMichael
Copy link
Contributor

RenderMichael commented Oct 23, 2024

@nvborisenko I found a few non-JSON related improvements we can make to the AOT story, I opened #14637

@RenderMichael
Copy link
Contributor

I opened an issue to improve the exception experience of what initially confused me: #14639

@nvborisenko
Copy link
Member Author

Seems success, we don't have reported issues related to json serialization. Thanks all, who participated in this. I deprioritized CDP, we are more interested in BiDi.

@RenderMichael
Copy link
Contributor

I think success for this can be measured by adding <IsAotCompatible> to true, and add the [RequiresUnreferencedCode] attribute for things that are not AOT-compatible. I can spin up a PR for the minimal changes required for this

@nvborisenko
Copy link
Member Author

Please no, then we will create new issue like "Road to be trimming friendly".

@RenderMichael
Copy link
Contributor

AOT is a subset of trimmable (or put another way, trim-friendly is a pre-requisite of AOT-friendly)

Besides, aside from JSON, I saw there were only 2 or 3 spots that need any changes

@nvborisenko
Copy link
Member Author

nvborisenko commented Nov 18, 2024

I received a lot of issues privately related to json serialization. In major cases users used custom class and they provided an instance of it as object. Object is expected according API, and they got JsonTypeInfo metadata for type '*' was not provided by TypeInfoResolver of type 'OpenQA.Selenium.CommandJsonSerializerContext' exception. @RenderMichael provided elegant fix (will be in 4.27). Seems we will forget about this issue for "classic" WebDriver commands. Thank you, Michael, great job!

@RenderMichael
Copy link
Contributor

Happy to contribute!

I have a PR addressing every AOT concern aside from JSON. It was a lot simpler than I thought. #14637

@NCLnclNCL
Copy link

Happy to contribute!

I have a PR addressing every AOT concern aside from JSON. It was a lot simpler than I thought. #14637

Hi,do you know anything about python, i want to convert python nodriver library to c#

@larsbloch
Copy link

Hi

My current goal is to migrate my selenium project into a Native Aot application.

I get errors when i start a new DevToolsSessions

OpenQA.Selenium.WebDriverException: 'Unexpected error creating WebSocket DevTools session.'
InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.

        var driver = new ChromeDriver();
        var devToolsSession = driver.GetDevToolsSession(); <- Error here

I am not familie with the internals of Selenium but maybe you can tell me if my project is a lost cause or if the problems are going to be handled by some of the hard work you seem to be doing in regards to AOT ?

@nvborisenko
Copy link
Member Author

GetDevToolsSession is not compatible with AOT yet, please track CDP section in the original post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants