I have the following code that I use to download the last chromedriver to a specific folder:
(new-object System.Net.WebClient).DownloadFile("https://chromedriver.storage.googleapis.com/$($ChromeDriverLatestVersion)/chromedriver_win32.zip", "C:\path\Debug\chromedriver.zip")
where $ChromeDriverLatestVersion
is the number of the last release. This code works. However, if you put both arguments into strings, the second argument generates an exception. Example:
(new-object System.Net.WebClient).DownloadFile("$Chrome", "$ZipChromePath")
System.Management.Automation.MethodInvocationException: Exception calling "DownloadFile" with "2" argument(s): "The path is not of a legal form." ---> System.ArgumentException: The path is not of a legal form.
at System.IO.Path.NewNormalizePath(String path, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetFullPathInternal(String path)
at System.Net.WebClient.GetUri(String path)
at System.Net.WebClient.DownloadFile(String address, String fileName)
at CallSite.Target(Closure , CallSite , Object , String , String )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction'2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
I know it's the second argument that causes the exception, because
(new-object System.Net.WebClient).DownloadFile("$Chrome", "C:\path\Debug\chromedriver.zip")
The code runs. I just can not explain why ...