Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Tools.AndroidSdk] Fix quotes in %PATH% or %PATHEXT% (#…
…112) Fixes: https://developercommunity.visualstudio.com/t/illegal-character-exception-in-xamarinandroid-afte/1363149 In 16.9 we are getting some reports of: (_ResolveSdks target) -> error XARSD7004: System.ArgumentException: Illegal characters in path. error XARSD7004: at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) error XARSD7004: at System.IO.Path.Combine(String path1, String path2) error XARSD7004: at Xamarin.Android.Tools.ProcessUtils.<FindExecutablesInDirectory>d__9.MoveNext() error XARSD7004: at Xamarin.Android.Tools.ProcessUtils.<FindExecutablesInPath>d__8.MoveNext() error XARSD7004: at Xamarin.Android.Tools.AndroidSdkBase.<GetAllAvailableAndroidNdks>d__73.MoveNext() error XARSD7004: at Xamarin.Android.Tools.AndroidSdkWindows.<GetAllAvailableAndroidNdks>d__43.MoveNext() error XARSD7004: at Xamarin.Android.Tools.AndroidSdkBase.GetValidNdkPath(String ctorParam) error XARSD7004: at Xamarin.Android.Tools.AndroidSdkBase.Initialize(String androidSdkPath, String androidNdkPath, String javaSdkPath) error XARSD7004: at Xamarin.Android.Tools.AndroidSdkWindows.Initialize(String androidSdkPath, String androidNdkPath, String javaSdkPath) error XARSD7004: at Xamarin.Android.Tools.AndroidSdkInfo..ctor(Action`2 logger, String androidSdkPath, String androidNdkPath, String javaSdkPath) error XARSD7004: at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshAndroidSdk(String sdkPath, String ndkPath, String javaPath, TaskLoggingHelper logHelper) error XARSD7004: at Xamarin.Android.Tasks.ResolveSdks.RunTask() error XARSD7004: at Xamarin.Android.Tasks.AndroidTask.Execute() It appears this is simply a call like this failing: Path.Combine ("foo", "\"") Path.Combine ("\"", "foo") The most likely reason for certain customers to get this exception is because an environment variable contains quotes, e.g. rem Windows CMD.EXE set PATH='…' On Windows+CMD.EXE, the `'` (or `"`) is *not* needed, even if the value has spaces: rem Can cause Pain and Suffering™ set PATH="C:\This Directory Has Spaces;%PATH%" rem Good and Proper™ set PATH=C:\This Directory Has Spaces;%PATH% I could reproduce this in a test by setting `%PATH%` or `%PATHEXT%` to invalid names. For `%PATH%`, I could simply add a `Directory.Exists()` check in the place that makes sense. However, I think a `try`/`catch` of `ArgumentException` is the only way to handle `%PATHEXT%`? I had to put this in two places where the new test found an issue.
- Loading branch information