Skip to content

CoreRT AOT Execution Incompatibility #8549

@josephmoresena

Description

@josephmoresena

🐛 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions