@@ -300,14 +300,14 @@ public EnvironmentEntry(Xml.LaunchOptions.EnvironmentEntry xmlEntry)
300300
301301 public EnvironmentEntry ( Json . LaunchOptions . Environment jsonEntry )
302302 {
303- this . Name = LaunchOptions . RequireAttribute ( jsonEntry . Name , nameof ( jsonEntry . Name ) ) ;
304- this . Value = jsonEntry . Value ?? string . Empty ;
303+ this . Name = LaunchOptions . RequireAttribute ( jsonEntry . Name , "environment.name" ) ;
304+ this . Value = jsonEntry . Value ;
305305 }
306306
307307 public EnvironmentEntry ( string name , string ? value )
308308 {
309309 this . Name = name ;
310- this . Value = value ?? string . Empty ;
310+ this . Value = value ;
311311 }
312312
313313 /// <summary>
@@ -316,9 +316,9 @@ public EnvironmentEntry(string name, string? value)
316316 public string Name { get ; private set ; }
317317
318318 /// <summary>
319- /// [Required] Value of the environment variable
319+ /// Value of the environment variable, or null to delete it
320320 /// </summary>
321- public string Value { get ; private set ; }
321+ public string ? Value { get ; private set ; }
322322 }
323323
324324 public sealed class SourceMapEntry
@@ -380,9 +380,14 @@ public static ReadOnlyCollection<SourceMapEntry> CreateCollection(Xml.LaunchOpti
380380
381381 public static ReadOnlyCollection < SourceMapEntry > CreateCollection ( Dictionary < string , object > ? source )
382382 {
383- var sourceMaps = new List < SourceMapEntry > ( source ? . Keys . Count ?? 0 ) ;
383+ int count = source ? . Keys . Count ?? 0 ;
384+ if ( count == 0 )
385+ {
386+ return new ReadOnlyCollection < SourceMapEntry > ( Array . Empty < SourceMapEntry > ( ) ) ;
387+ }
384388
385- foreach ( var item in source ?? new Dictionary < string , object > ( ) )
389+ var sourceMaps = new List < SourceMapEntry > ( ) ;
390+ foreach ( var item in source ! )
386391 {
387392 string compileTimePath = item . Key ;
388393 string ? editorPath = null ;
@@ -880,7 +885,7 @@ protected set
880885 private string ? _exePath ;
881886
882887 /// <summary>
883- /// [Required] Path to the executable file. This could be a path on the remote machine (for Pipe transport)
888+ /// Path to the executable file. This could be a path on the remote machine (for Pipe transport)
884889 /// or the local machine (Local transport).
885890 /// </summary>
886891 public virtual string ? ExePath
@@ -1383,19 +1388,25 @@ public static LaunchOptions GetInstance(HostConfigurationStore? configStore, str
13831388
13841389 // if the customLauncher element is present then try using the custom launcher implementation from the config store
13851390 JToken ? customLauncherToken = parsedOptions [ "customLauncher" ] ;
1386- if ( customLauncherToken is not null && ! IsNullOrWhiteSpace ( customLauncherToken . Value < string > ( ) ) )
1391+ if ( customLauncherToken is not null && customLauncherToken . Value < string > ( ) is string customLauncherName && ! IsNullOrWhiteSpace ( customLauncherName ) )
13871392 {
1388- string customLauncherName = customLauncherToken . Value < string > ( ) ?? string . Empty ;
1389- var jsonLauncher = configStore ? . GetCustomLauncher ( customLauncherName ) ;
1393+ if ( configStore is null || eventCallback is null )
1394+ {
1395+ throw new InvalidLaunchOptionsException ( MICoreResources . Error_UnknownLaunchOptions ) ;
1396+ }
1397+
1398+ var jsonLauncher = configStore . GetCustomLauncher ( customLauncherName ) ;
13901399 if ( jsonLauncher == null )
13911400 {
13921401 throw new ArgumentException ( string . Format ( CultureInfo . CurrentCulture , MICoreResources . Error_UnknownCustomLauncher , customLauncherName ) ) ;
13931402 }
1394- if ( jsonLauncher as IPlatformAppLauncher == null )
1403+
1404+ if ( jsonLauncher is not IPlatformAppLauncher platformAppLauncher )
13951405 {
13961406 throw new ArgumentException ( string . Format ( CultureInfo . CurrentCulture , MICoreResources . Error_LauncherNotFound , customLauncherName ) ) ;
13971407 }
1398- launchOptions = ExecuteLauncher ( configStore , ( IPlatformAppLauncher ) jsonLauncher , exePath , args , dir , parsedOptions , eventCallback , targetEngine , logger ) ;
1408+
1409+ launchOptions = ExecuteLauncher ( configStore , platformAppLauncher , exePath , args , dir , parsedOptions , eventCallback , targetEngine , logger ) ;
13991410 }
14001411 else if ( parsedOptions [ "pipeTransport" ] is JToken pipeTransportToken && pipeTransportToken . HasValues )
14011412 {
@@ -1508,7 +1519,7 @@ public static LaunchOptions GetInstance(HostConfigurationStore? configStore, str
15081519
15091520 if ( clsidLauncher != Guid . Empty )
15101521 {
1511- if ( launcherXmlOptions is null )
1522+ if ( launcherXmlOptions is null || configStore is null )
15121523 {
15131524 throw new InvalidLaunchOptionsException ( MICoreResources . Error_UnknownLaunchOptions ) ;
15141525 }
@@ -1517,7 +1528,7 @@ public static LaunchOptions GetInstance(HostConfigurationStore? configStore, str
15171528 }
15181529 else if ( launcher != null )
15191530 {
1520- if ( launcherXmlOptions is null )
1531+ if ( launcherXmlOptions is null || configStore is null || eventCallback is null )
15211532 {
15221533 throw new InvalidLaunchOptionsException ( MICoreResources . Error_UnknownLaunchOptions ) ;
15231534 }
@@ -1560,8 +1571,8 @@ public static LaunchOptions CreateForAttachRequest(Microsoft.VisualStudio.Debugg
15601571 Logger logger )
15611572 {
15621573 var suppOptions = GetOptionsFromFile ( logger ) ;
1563- string connection ;
1564- ( ( IDebugPort2 ) unixPort ) . GetPortName ( out connection ! ) ;
1574+ string ? connection ;
1575+ ( ( IDebugPort2 ) unixPort ) . GetPortName ( out connection ) ;
15651576 AttachOptionsForConnection ? attachOptions = null ;
15661577 if ( suppOptions != null && suppOptions . AttachOptions != null )
15671578 {
@@ -2175,13 +2186,8 @@ public static int RequirePortAttribute(int attributeValue, string attributeName)
21752186 return attributeValue ;
21762187 }
21772188
2178- private static LaunchOptions ExecuteLauncher ( HostConfigurationStore ? configStore , Guid clsidLauncher , string exePath , string ? args , string ? dir , object launcherXmlOptions , IDeviceAppLauncherEventCallback ? eventCallback , TargetEngine targetEngine , Logger ? logger )
2189+ private static LaunchOptions ExecuteLauncher ( HostConfigurationStore configStore , Guid clsidLauncher , string exePath , string ? args , string ? dir , object launcherXmlOptions , IDeviceAppLauncherEventCallback ? eventCallback , TargetEngine targetEngine , Logger ? logger )
21792190 {
2180- if ( configStore is null )
2181- {
2182- throw new ArgumentNullException ( nameof ( configStore ) ) ;
2183- }
2184-
21852191 var deviceAppLauncher = HostLoader . VsCoCreateManagedObject ( configStore , clsidLauncher ) as IPlatformAppLauncher ;
21862192 if ( deviceAppLauncher == null )
21872193 {
@@ -2190,15 +2196,15 @@ private static LaunchOptions ExecuteLauncher(HostConfigurationStore? configStore
21902196 return ExecuteLauncher ( configStore , deviceAppLauncher , exePath , args , dir , launcherXmlOptions , eventCallback , targetEngine , logger ) ;
21912197 }
21922198
2193- private static LaunchOptions ExecuteLauncher ( HostConfigurationStore ? configStore , IPlatformAppLauncher deviceAppLauncher , string exePath , string ? args , string ? dir , object launcherOptions , IDeviceAppLauncherEventCallback ? eventCallback , TargetEngine targetEngine , Logger ? logger )
2199+ private static LaunchOptions ExecuteLauncher ( HostConfigurationStore configStore , IPlatformAppLauncher deviceAppLauncher , string exePath , string ? args , string ? dir , object launcherOptions , IDeviceAppLauncherEventCallback eventCallback , TargetEngine targetEngine , Logger ? logger )
21942200 {
21952201 bool success = false ;
21962202
21972203 try
21982204 {
21992205 try
22002206 {
2201- deviceAppLauncher . Initialize ( configStore ?? throw new ArgumentNullException ( nameof ( configStore ) ) , eventCallback ?? throw new ArgumentNullException ( nameof ( eventCallback ) ) ) ;
2207+ deviceAppLauncher . Initialize ( configStore , eventCallback ) ;
22022208 deviceAppLauncher . SetLaunchOptions ( exePath , args ?? string . Empty , dir ?? string . Empty , launcherOptions , targetEngine ) ;
22032209 }
22042210 catch ( Exception e ) when ( ! ( e is InvalidLaunchOptionsException ) && ExceptionHelper . BeforeCatch ( e , logger , reportOnlyCorrupting : true ) )
0 commit comments