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

CoreRT AOT Execution Incompatibility #8549

Closed
josephmoresena opened this issue Jul 19, 2020 · 2 comments
Closed

CoreRT AOT Execution Incompatibility #8549

josephmoresena opened this issue Jul 19, 2020 · 2 comments

Comments

@josephmoresena
Copy link

josephmoresena commented Jul 19, 2020

🐛 Bug Report

It is not possible to run a CoreRT compiled program using Selenium + FirefoxDriver. An exception occurs when trying to create instances of FirefoxOptions and FirefoxDriver.

To Reproduce

Simply follow the instructions to create a console executable from the CoreRT repo and call some constructor for the FirefoxProfile and FirefoxDriver classes.

Compiling the program using CoreRT and when executing, an exception will appear in the lines of the call of said constructors due to the use of System.Reflection.Assembly.GetCallingAssembly () since it is not supported in the AOT environment of CoreRT.

Detailed steps to reproduce the behavior:

Expected behavior

It was expected to be able to instantiate objects using the constructors of the FirefoxDriver and FirefoxProfile classes without getting any kind of exception or at least any solvable from the rd.xml file.

Test script or set of commands reproducing this issue

using System;
using System.Runtime.InteropServices;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Linq;
using System.Threading;

namespace ConsoleApp1
{
	class Program
	{
		static Boolean isEncodingRegistered = !RuntimeInformation.FrameworkDescription.Contains("Core");

		static FirefoxDriverService service;
		static IWebDriver webDriver;

		private static void RegisterEncoding()
		{
			if (!isEncodingRegistered)
			{
				Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
				isEncodingRegistered = true;
			}
		}

		static Program()
		{
			RegisterEncoding();
			string driverPath = $@"{AppDomain.CurrentDomain.BaseDirectory}";

			service = FirefoxDriverService.CreateDefaultService(driverPath);
			Console.WriteLine("SERVICE");
			FirefoxOptions options = new FirefoxOptions();
			Console.WriteLine("OPTIONS");
			options.AcceptInsecureCertificates = true;
			options.UseLegacyImplementation = true;
			options.Profile = new FirefoxProfile();
			Console.WriteLine("PROFILE");
			webDriver = new FirefoxDriver(service, options);
			Console.WriteLine("DRIVER");
			webDriver.Navigate().GoToUrl("https://www.selenium.dev/");			
			webDriver.FindElements(By.ClassName("nav-item")).FirstOrDefault().Click();
			webDriver.FindElement(By.Name("search")).SendKeys("Nothing");
			webDriver.FindElement(By.Name("search")).SendKeys(Keys.Enter);
		}

		static void Main(string[] args)
		{
			Thread.Sleep(250);
			try
			{
				webDriver.FindElement(By.ClassName("gsc-search-button-v2"));
				Console.WriteLine("Element found");
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex);
				Console.WriteLine("Element not found");
			}


			Console.WriteLine("Press any key to exit.");
			Console.ReadKey();

			webDriver.Close();
			service.Dispose();
		}
	}
}

Execution results:

SERVICE
OPTIONS
Unhandled Exception: System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Reflection.Assembly.GetCallingAssembly() + 0x5e
   at OpenQA.Selenium.Internal.ResourceUtilities.GetResourceStream(String, String) + 0xd0
   at OpenQA.Selenium.Firefox.FirefoxProfile.ReadDefaultPreferences() + 0x2b
   at OpenQA.Selenium.Firefox.FirefoxProfile..ctor(String, Boolean) + 0x73
   at ConsoleApp1.Program..cctor() + 0x14b
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xd3
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x186
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0xd
   at ConsoleApp1.Program.Main(String[]) + 0x10
   at ConsoleApp1!<BaseAddress>+0x6a1d15

Environment

OS: Windows 10 LTSC 2019
Browser: Firefox x64
Browser version: 52.8.0
Browser Driver version: GeckoDriver 0.26.0
Language Bindings version: C# NetCoreApp 3.1

@diemol
Copy link
Member

diemol commented Mar 10, 2021

Apologies for the late reply.

I am not familiar with CoreRT AOT, but I found this repository that is on read-only state now... Then, the readme of the repo sent me to https://github.com/dotnet/runtimelab/tree/feature/NativeAOT, which explicitly says that it is on a experimental state.

Therefore, and assuming I found the repos that actually are related to this, bumping into an issue is completely normal, due to the experimental nature of the referenced project.

We try to support as many environments as possible, given their wide usage, but I'd say in this case that we won't dig into this unless this environment becomes vital for the C# Selenium community.

I'll close this for now, but if I am wrong about my comments above, we can reopen this and check further.

Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants