Closed cltsang closed 4 years ago
Can you reproduce it with normal Firefox, not TorBrowser?
No, unfortunately. So I'm not even sure where I should start looking.
Tor Browser is not supported at present, watch #4239
I'm going to close this for now since there might tons of issues with Tor Browser + Selenium, but this is fine as long as it's not supported.
Feel free to jump in the conversation in #4239.
@p0deje Can this be reopened? This is not a Tor browser issue. I can reproduce with regular Firefox, running on .net core 2.0 on Windows.
Reproduction code:
using System;
using OpenQA.Selenium.Firefox;
namespace FirefoxTest
{
class Program
{
static void Main(string[] args)
{
const string geckoDriverDirectory = @"C:\Program Files\GeckoDriver";
FirefoxOptions firefoxOptions = new FirefoxOptions()
{
Profile = new FirefoxProfile()
{
DeleteAfterUse = true,
},
};
firefoxOptions.SetPreference("javascript.enabled", false);
using (FirefoxDriver driver = new FirefoxDriver(geckoDriverDirectory, firefoxOptions))
{
driver.Quit();
}
}
}
}
Error:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.IO.Compression.ZipStorer' threw an exception. ---> System.NotSupportedException: No data is available for encoding 437. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
at System.Text.Encoding.GetEncoding(Int32 codepage)
at System.IO.Compression.ZipStorer..cctor()
--- End of inner exception stack trace ---
at System.IO.Compression.ZipStorer.WriteLocalHeader(ZipFileEntry& zipFileEntry)
at System.IO.Compression.ZipStorer.AddStream(CompressionMethod compressionMethod, Stream sourceStream, String fileNameInZip, DateTime modificationTimeStamp, String fileEntryComment)
at System.IO.Compression.ZipStorer.AddFile(CompressionMethod compressionMethod, String sourceFile, String fileNameInZip, String fileEntryComment)
at OpenQA.Selenium.Firefox.FirefoxProfile.ToBase64String()
at OpenQA.Selenium.Firefox.FirefoxOptions.GenerateFirefoxOptionsDictionary()
at OpenQA.Selenium.Firefox.FirefoxOptions.ToCapabilities()
at OpenQA.Selenium.Firefox.FirefoxDriver.ConvertOptionsToCapabilities(FirefoxOptions options)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(String geckoDriverDirectory, FirefoxOptions options)
at FirefoxTest.Program.Main(String[] args) in D:\documents\visual studio 2017\Projects\FirefoxTest\FirefoxTest\Program.cs:line 21
Looks like the ZipStorer code needs encoding 437. .NET core removes built-in support for many less common encodings, including 437. To make the encoding available in .NET core, you need to reference the System.Text.Encoding System.Text.Encoding.CodePages Nuget package and somewhere before Encoding.GetEncoding(437)
gets called, make sure to call Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
.
As a workaround users can do the above steps in their own code.
Thanks very much for the workaround @LHCGreg - although I think CodePagesEncodingProvider
lives in the System.Text.Encoding.CodePages nuget package rather than System.Text.Encoding
Yes, sorry, I got the link correct but the name wrong.
Same exception is thrown when uploading file with RemoteWebDriver
, eg:
if (_driver.GetType() == typeof(RemoteWebDriver))
{
((RemoteWebDriver)_driver).FileDetector = new LocalFileDetector();
}
FileInput.SendKeys(filePath);
@LHCGreg workaround works here also. Thanks a lot!
Also confirmed workaround works for netcore2.2 + chromedvier
I don’t want to lock discussion on this issue. The ZipStorer code has been removed entirely from the code base for the 4.0 development cycle. Users should at least give the 4.0 alpha 1 before commenting.
As the most recent comment says, please use the referenced version and keep an eye on the upcoming releases.
Will close this issue since it has been fixed on trunk
Meta -
OS: Windows 10 and Mac OS
Selenium Version: WebDriver 3.6.0, C#
Browser: Tor Browser
Browser Version: 7.0.6 (based on Firefox 52.4.0 (64-Bit))
Expected Behavior -
According to the Nuget page, the WebDriver supports .Net Standard 2.0.
Actual Behavior -
when running on a .NET Core 2.0 console project, I encountered an exception
System.TypeInitializationException: The type initializer for 'System.IO.Compression.ZipStorer' threw an exception. ---> System.NotSupportedException: No data is available for encoding 437.
Steps to reproduce -
Just start a new project and instantiate FirefoxDriver by
Am I doing anything incorrectly here? Please advise, thank you.