Home: Illegal characters in path while nuget restore

Created on 23 Jul 2019  路  25Comments  路  Source: NuGet/Home

I have CSharp project available on my local machine.
image

Here If I do nuget update SeleniumNUnitParam.sln I am getting Illegal characters in path.

image

Strange thing is I am able to build and deploy the same project using Visual Studio.
But, Not able to perform the same using command line.

Please let me know if I am wrong or any changes needs to be updated.

ErrorHandling Icebox 3 NuGet.exe Packages.Config Bug help wanted

All 25 comments

Hi, can you add "-verbosity detail" when you run nuget update command and paste the output here? Thanks!

@heng-liu : Here Are the Logs for nuget update

PS C:\Program Files (x86)\Jenkins\workspace\CSharpFreestyle> nuget update SeleniumNUnitParam.sln -verbosity detail
NuGet Version: 5.1.0.6013
Illegal characters in path.
System.ArgumentException: Illegal characters in path.
   at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
   at System.IO.Path.Combine(String path1, String path2)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at NuGet.CommandLine.MsBuildUtility.GetMSBuild()
   at NuGet.CommandLine.MsBuildUtility.GetMsBuildToolset(String userVersion, IConsole console)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at NuGet.CommandLine.UpdateCommand.<ExecuteCommandAsync>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

Looks like the PATH environment variable is not set properly. Can you please check if it contains Illegal characters? Or you can paste it here so I can repro. Thanks!

@heng-liu
In the System Variable --->> Path -->>
I have Below Variables set

E:\Software\Nuget\nuget.exe
E:\Software\Nuget

This is where I have my nuget.exe

image

I just wanted to update I am able to use other nuget commands like nuget list.

image

But the issue withnuget restore and nuget update remains the same

Please paste the complete list of PATH.
You may use $env:PATH if you use powershell.

@heng-liu Please Find below the complete list of PATH.

C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\ProgramData\DockerDesktop\version-bin
C:\Program Files\Docker\Docker\Resources\bin
C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services
C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services
%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static
C:\Program Files\dotnet\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\
C:\Program Files\Microsoft SQL Server\120\DTS\Binn\
%SYSTEMROOT%\System32\OpenSSH\
C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\
C:\Windows\System32\cmd.exe
C:\Program Files\Java\jdk1.8.0_211\bin
%MAVEN_HOME%\bin
C:\Program Files\Git\cmd
C:\ProgramData\chocolatey\bin
C:\Program Files\Java\jdk1.8.0_211\
E:\Software\ChromeDriver\
C:\Windows\System32;
C:\Windows\System32\wbem;
E:\Software\Nuget\nuget.exe
E:\Software\Nuget

You have some real oddities in there: PATH should contain only folders, but you have C:\Windows\System32\cmd.exe and the two entries ending with semicolons are suspicious also. I suggest you clean these up and try again.

@Paul-Dempsey I have removed the variable C:\Windows\System32\cmd.exe Apart from this wat else need to be changed ?? Please find below updated environment variables.

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files\Java\jdk1.8.0_211\bin;E:\Software\Maven\apache-maven-3.6.1\bin;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files\Java\jdk1.8.0_211\;E:\Software\ChromeDriver\;"C:\Windows\System32;";"C:\Windows\System32\wbem;";E:\Software\Nuget\nuget.exe;E:\Software\Nuget;C:\Users\hp\AppData\Local\Microsoft\WindowsApps

No idea, just pointing out some things that looked odd. So did that change help?

@Paul-Dempsey : No It didn't

@heng-liu : can you please guide me. If any specific troubleshooting steps need to be performed?

Hi, I'm not sure if double quotes would work, can you try to remove them?
I went through the paths, and it seems no one could have MSbuild.exe inside. As you mentioned you can build with Visual Studio, so you have Visual Studio installed, right? Can you add the path of MSbuild.exe to PATH?

@heng-liu
Hello,
The path contains all the values without quotes. Not sure how it's getting displayed while $env:PATH

image

Yes, I have a Visual Studio installed on my machine.
As Per suggetion, I have Added the path of MSBuild into PATH Variables.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe

After this, I have also tried the restart of the machine.

Still, the issue is the same.

I'm experiencing this same issue. If I use an older version 4.9.4 of nuget.exe, it works fine, however, the latest one 5.1.0 is the culprit.

I've never seen .exe in the PATH environment -- only folders. What happens when you remove the exe's? The other unusual thing is variable references %...%

I'm having the same issue with this command:

PS C:\Users\user\source\repos\ProjectDir> C:/Users/user/source/repos/ProjectDir/tools/NuGet.exe restore C:/Users/user/source/repos/ProjectDir/ProjectSolution.sln -Verbosity detailed
NuGet Version: 5.1.0.6013
Illegal characters in path...

Is there any workaround?

After some testing I found the culprit, one of my environment variables was like this "%JAVA_HOME%\bin;%PATH%" (including the quotes), which was being translated to "C:\Program Files\Java\jre1.8.0_191\bin (with only one quote at the beginning).

When I changed the value of this variable to simply %JAVA_HOME%\bin;%PATH% (without quotes) Nuget worked as expected, but I'm not sure if the modification will have any side effects in any other application.

If I can state, in my specific case, it seems to me that Nuget's behavior is somewhat wrong or misleading, it should at least state more clearly what is the problem or, even betther, just ignore the fault variable.

Ran into this same issue as well using nu get 5. Specifically

NuGet Version: 5.1.0.6013

18:14:24  d:\jenkins\workspace\XXXX-host_feature_GTS-131>buildtools\nuget\nuget.exe restore src\Host.sln 
18:14:24  Illegal characters in path.

As suggested, I checked my $env:path and noticed the following problem - one of the entries was enclosed in quotation marks like so"C:\Program Files\Java\jre1.8.0_221\bin". After removal ,it worked fine. This behavior appears confined to nuget 5.x.x releases, older projects running on the same server with same environment variables don't have the issue.

I turned on the verbosity and the stack trace is here:

18:58:38  NuGet Version: 5.1.0.6013
18:58:38  Illegal characters in path.
18:58:38  System.ArgumentException: Illegal characters in path.
18:58:38     at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
18:58:38     at System.IO.Path.Combine(String path1, String path2)
18:58:38     at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
18:58:38     at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
18:58:38     at NuGet.CommandLine.MsBuildUtility.GetMSBuild()
18:58:38     at NuGet.CommandLine.MsBuildUtility.GetMsBuildToolset(String userVersion, IConsole console)
18:58:38     at System.Lazy`1.CreateValue()
18:58:38     at System.Lazy`1.LazyInitValue()
18:58:38     at NuGet.CommandLine.RestoreCommand.ProcessSolutionFile(String solutionFileFullPath, PackageRestoreInputs restoreInputs)
18:58:38     at NuGet.CommandLine.RestoreCommand.<DetermineRestoreInputsAsync>d__46.MoveNext()
18:58:38  --- End of stack trace from previous location where exception was thrown ---
18:58:38     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
18:58:38     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
18:58:38     at NuGet.CommandLine.RestoreCommand.<ExecuteCommandAsync>d__36.MoveNext()
18:58:38  --- End of stack trace from previous location where exception was thrown ---
18:58:38     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
18:58:38     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
18:58:38     at NuGet.CommandLine.Command.Execute()
18:58:38     at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

After checking that since the error is in parsing the environment variables looking for msbuild you can also work around it by specifying the msbuildpath in the nuget command like so:
nuget.exe restore src\Host.sln -msbuildpath "C:\Program Files (x86)\MSBuild\14.0\Bin"

I guess is it worth submitting a pr @heng-liu to at least give a better exception up from MsbuildUtility or some fancier parsing to ignore path issues in that utility? I'm willing to give it a go, but don't want to do the work without discussion

I had same issue, it was working fine for all users, but was failing for one specific user (it was build service account in my case). After verifying all environment variable couldn't find anything related. Later I deleted the nuget.confing from C:\Users\\AppData\Roaming\NuGet and cache folder from C:\Users\\AppData\Local\NuGet and then all started working as expected.

I'm also experiencing this after updating nuget.exe from version 4 to latest

I had to change the nuget restore command from
"C:\Program Files (x86)\Jenkins\workspace\.nuget\NuGet.exe" install "C:\Program Files (x86)\Jenkins\workspace\Extensions\packages.config" -source "https://api.nuget.org/v3/index.json;https://www.nuget.org/api/v2/;http://nuget/nuget/" -NonInteractive -RequireConsent -solutionDir "C:\Program Files (x86)\Jenkins\workspace\"

to

"C:\Program Files (x86)\Jenkins\workspace\.nuget\NuGet.exe" install "C:\Program Files (x86)\Jenkins\workspace\Extensions\packages.config" -source "https://api.nuget.org/v3/index.json;https://www.nuget.org/api/v2/;http://nuget/nuget/" -NonInteractive -RequireConsent -solutionDir "C:\Program Files (x86)\Jenkins\workspace\\"

note the extra "\" at the end

Please make sure you are passing in the MSBuildPath using the Visual Studio version of MSBuild, the one that installs under the VS directory. Attempting to use the MSBuild suggestions mentioned above will all fail with this error.

18:58:38 NuGet Version: 5.1.0.6013
18:58:38 Illegal characters in path.
18:58:38 System.ArgumentException: Illegal characters in path.
18:58:38 at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
18:58:38 at System.IO.Path.Combine(String path1, String path2)
18:58:38 at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() 18:58:38 at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source, Func2 predicate) 18:58:38 at NuGet.CommandLine.MsBuildUtility.GetMSBuild() 18:58:38 at NuGet.CommandLine.MsBuildUtility.GetMsBuildToolset(String userVersion, IConsole console) 18:58:38 at System.Lazy1.CreateValue()
18:58:38 at System.Lazy`1.LazyInitValue()
18:58:38 at NuGet.CommandLine.RestoreCommand.ProcessSolutionFile(String solutionFileFullPath, PackageRestoreInputs restoreInputs)
18:58:38 at NuGet.CommandLine.RestoreCommand.d__46.MoveNext()
18:58:38 --- End of stack trace from previous location where exception was thrown ---
18:58:38 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
18:58:38 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
18:58:38 at NuGet.CommandLine.RestoreCommand.d__36.MoveNext()
18:58:38 --- End of stack trace from previous location where exception was thrown ---
18:58:38 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
18:58:38 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
18:58:38 at NuGet.CommandLine.Command.Execute()
18:58:38 at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

I had this issue on 5.4.0. I was unable to spot anything strange with my path variable though, so I was forced to downgrade to 4.9.4, which worked fine. As Lukkian said, nuget should probably just ignore any faulty paths, rather than fail entirely.

Hey all,

We think the appropriate fix for this issue to improve the error message.
We do not think we'll be able to get to this soon enough, but we would consider taking a fix if anyone is interested.

I just encountered this message and read this thread. Turned out that I had an empty entry in the path. That is, ;; -- two semicolons with nothing in between. That was enough to freak nuget out.

I just encountered this, it was a mal-formed environment variable.
Why don't you nuget programmers just make this error a bit more verbose, so we don't have to spam google with search queries all day, and read through long endless threads like this.

One lousy helpful message is all it takes to fix this guys!

Was this page helpful?
0 / 5 - 0 ratings