Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit cf9d325

Browse files
jpobstjonpryor
authored andcommitted
[AndroidSdkWindows] Guard against exception checking registry (#79)
Fixes: https://developercommunity.visualstudio.com/content/problem/883179/ilegal-characters-in-path-after-fresh-install.html Somehow, a registry key contains invalid path characters. This causes an `ArgumentException` from `AndroidSdkWindows.CheckRegistryKeyForExecutable()`: 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 Xamarin.Android.Tools.AndroidSdkWindows.CheckRegistryKeyForExecutable(UIntPtr key, String subkey, String valueName, Wow64 wow64, String subdir, String exe) at Xamarin.Android.Tools.AndroidSdkWindows.<GetAllAvailableAndroidSdks>d__37.MoveNext() at System.Linq.Enumerable.<DistinctIterator>d__64`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Xamarin.Android.Tools.AndroidSdkBase.get_AllAndroidSdks() at Xamarin.Android.Tools.AndroidSdkBase.Initialize(String androidSdkPath, String androidNdkPath, String javaSdkPath) at Xamarin.Android.Tools.AndroidSdkWindows.Initialize(String androidSdkPath, String androidNdkPath, String javaSdkPath) at Xamarin.Android.Tools.AndroidSdkInfo..ctor(Action`2 logger, String androidSdkPath, String androidNdkPath, String javaSdkPath) Handle the `ArgumentException` by wrapping the body of `CheckRegistryKeyForExecutable()` within a `try/catch` block and catch all exceptions. If an exception is thrown, there is no executable of interest.
1 parent 310c5cf commit cf9d325

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkWindows.cs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,23 @@ public override void SetPreferredAndroidNdkPath (string path)
303303
#region Helper Methods
304304
privatestaticboolCheckRegistryKeyForExecutable(UIntPtrkey,stringsubkey,stringvalueName,RegistryEx.Wow64wow64,stringsubdir,stringexe)
305305
{
306-
stringkey_name=string.Format(@"{0}\{1}\{2}",key==RegistryEx.CurrentUser?"HKCU":"HKLM",subkey,valueName);
306+
try{
307+
stringkey_name=string.Format(@"{0}\{1}\{2}",key==RegistryEx.CurrentUser?"HKCU":"HKLM",subkey,valueName);
307308

308-
varpath=NullIfEmpty(RegistryEx.GetValueString(key,subkey,valueName,wow64));
309+
varpath=NullIfEmpty(RegistryEx.GetValueString(key,subkey,valueName,wow64));
309310

310-
if(path==null){
311-
returnfalse;
312-
}
311+
if(path==null){
312+
returnfalse;
313+
}
313314

314-
if(!ProcessUtils.FindExecutablesInDirectory(Path.Combine(path,subdir),exe).Any()){
315+
if(!ProcessUtils.FindExecutablesInDirectory(Path.Combine(path,subdir),exe).Any()){
316+
returnfalse;
317+
}
318+
319+
returntrue;
320+
}catch(Exception){
315321
returnfalse;
316322
}
317-
318-
returntrue;
319323
}
320324
#endregion
321325

0 commit comments

Comments
 (0)