cake-build/cake-vso

Exception calling "DownloadFile" with "2" argument(s): "The path is not of a legal form."

sreeraj-rajendran opened this issue · 8 comments

Per the the task configuration, nuget.exe will be downloaded from : https://dist.nuget.org/win-x86-commandline/latest/nuget.exe if the :Nuget.exe location" is unspecified.

The task seems to be failing with the error: ##[error]Exception calling "DownloadFile" with "2" argument(s): "The path is not of a legal form." When leaving this to default.

The behavior is the same when we try from a dummy pipeline - just with the cake task with no arguments as well.
However, enabling the option – “Use the Build Agent Nuget” works

Hello @gep13 - It looks like the change you made for 0.4.2 is causing this issue. The stack trace we saw is below. It seems like the build task, when we don't specify the location, is still interpreting $nugetExeDownloadLocation as an empty string rather than null, so when you replaced if($nugetExeDownloadLocation -eq "") with if($null -eq $nugetExeDownloadLocation), I'm guessing we get a $nugetExeDownloadLocation that is empty, so then it tries to DownloadFile from the url "" (blank), and then we get this exception

I'm also assuming you made this change because elsewhere you were getting $nugetExeDownloadLocation coming in as null and not "". Perhaps you could replace this and have a check for null or empty?
Edit: Something like one of these?
if($null -eq $nugetExeDownloadLocation -Or $nugetExeDownloadLocation -eq "")
if($null -eq $nugetExeDownloadLocation -Or $nugetExeDownloadLocation.trim() -eq "")

##[debug]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.
##[debug]   at System.IO.Path.NewNormalizePath(String path, Int32 maxPathLength, Boolean expandShortPaths)
##[debug]   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
##[debug]   at System.IO.Path.GetFullPathInternal(String path)
##[debug]   at System.Net.WebClient.GetUri(String path)
##[debug]   at System.Net.WebClient.DownloadFile(String address, String fileName)
##[debug]   at CallSite.Target(Closure , CallSite , Object , Object , Object )
##[debug]   --- End of inner exception stack trace ---
##[debug]   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
##[debug]   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
##[debug]   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
##[debug]   at System.Management.Automation.ScriptBlock.<>c__DisplayClass57_0.<InvokeWithPipe>b__0()
##[debug]   at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThreadCheck(Action action)
##[debug]   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
##[debug]   at System.Management.Automation.ScriptBlock.InvokeUsingCmdlet(Cmdlet contextCmdlet, Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args)
##[debug]   at Microsoft.PowerShell.Commands.ForEachObjectCommand.ProcessRecord()
##[debug]   at System.Management.Automation.CommandProcessor.ProcessRecord()
##[error]Exception calling "DownloadFile" with "2" argument(s): "The path is not of a legal form."
MO2k4 commented

Hey

i have a change and proposed it as a PR.

i would do a check like this

if (-Not $nugetExeDownloadLocation)

🎉 This issue has been resolved in version 0.4.3 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

gep13 commented

@sreeraj-rajendran @dannmichelson @MO2k4 @scott-the-programmer @danieljgmaclean @bkowalczyk88 This issue should now be resolved, with version 0.4.3 of the extension. Can you please let me know if you are still seeing problems.

Thanks

MO2k4 commented

Looks beautiful again, thanks for your fast response 👍

We have been experiencing this bug again since this morning:

##[debug]Exception:
##[debug]System.Management.Automation.MethodInvocationException: Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS secure channel." ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
##[debug]   at System.Net.WebClient.DownloadFile(Uri address, String fileName)
##[debug]   at CallSite.Target(Closure , CallSite , Object , Object , Object )
##[debug]   --- End of inner exception stack trace ---
##[debug]   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
##[debug]   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
##[debug]   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
##[debug]   at System.Management.Automation.ScriptBlock.<>c__DisplayClass57_0.<InvokeWithPipe>b__0()
##[debug]   at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThreadCheck(Action action)
##[debug]   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
##[debug]   at System.Management.Automation.ScriptBlock.InvokeUsingCmdlet(Cmdlet contextCmdlet, Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args)
##[debug]   at Microsoft.PowerShell.Commands.ForEachObjectCommand.ProcessRecord()
##[debug]   at System.Management.Automation.CommandProcessor.ProcessRecord()
##[error]Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS secure channel."
##[debug]Processed: ##vso[task.logissue type=error]Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS secure channel."

We are having this issue again with Cake.AzureDevOps v0.4.4, is it possible that the same bug as in v0.4.2 snug it's way back in?
EDIT:
Error was discovered, as of June 15th nuget does not support TLS 1.0 and 1.1.

@JoaoDiogoF For reference, there is a new issue because of the removal of TLS1.X.

I've also added a workaround, when you are in full control of the machine.

TLS 1.2 should be enabled to get it working. In PowerShell you can find out which protocols your system supports by running this code:

[Enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls12'
If the result is True then your system supports TLS 1.2. You can find out which protocols are being used by running:

If the result is True then TLS 1.2 is being used . However, you can add TLS 1.2 explicitly by using:

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
This should solve these problems.