Home

Disable shadow copy? ( chromedriver.exe cannot be refereced)

I have a script which uses chromedriver.exe. I cannot reference this file or I get:

CS0009 Metadata file 'C:\dimension\LinqPad\chromedriver.exe' could not be opened -- PE image doesn't contain managed metadata.

So I don't reference it. Half the time my script runs fine. Half the time I get

DriverServiceNotFoundException: The file [whatever]\AppData\Local\Temp\5\LINQPad5_azelyqpv\shadow_yoysfv\chromedriver.exe does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html

It half works, which gets the job done, but I would love if this could work properly. Is there a way to reference chromedriver.exe properly? Is there a way to not shadow? Or is there something else to do?

Cheers,
Daniel

Comments

  • Hi @dlwiii , here is my way:

    public static class WebDriverHelper
    {
        public static EdgeDriver CreateEdge()
        {
            string Version = "90.0.818.42";
            string baseDirectory = @"C:\_\3rd\edge-driver";
            string DestinationDirectory = @$"{baseDirectory}\{Version}";
            string BinaryPath = @$"{DestinationDirectory}\msedgedriver.exe";
    
            async Task EnsureInstalled()
            {
                if (!File.Exists(BinaryPath))
                {
                    Directory.CreateDirectory(DestinationDirectory.Dump());
                    using var http = new HttpClient();
                    using var stream = await http.GetStreamAsync(@$"https://msedgedriver.azureedge.net/{Version}/edgedriver_win64.zip".Dump("downloading driver..."));
                    using var archive = new ZipArchive(stream);
                    archive.ExtractToDirectory(DestinationDirectory);
    
                    Debug.Assert(File.Exists(BinaryPath), "web driver download failed?");
                    "driver downloaded and extracted".Dump();
                }
            }
    
            EnsureInstalled().GetAwaiter().GetResult();
            return new EdgeDriver(DestinationDirectory.Dump(), new EdgeOptions
            {
                UseChromium = true,
            });
        }
    
        public static ChromeDriver CreateChrome(ChromeOptions options = null)
        {
            var driverPath = new DirectoryInfo(typeof(ChromeDriver).Assembly.Location).Parent.Parent.Parent.Parent.Parent.FullName + @"\selenium.webdriver.chromedriver\94.0.4606.6100\driver\win32";
            options = options ?? new ChromeOptions();
            return new ChromeDriver(driverPath, options);
        }
    }
    
Sign In or Register to comment.