Skip to content

Commit 18a940b

Browse files
Copilotadamsitnik
andauthored
Allow null arguments in ProcessStartInfo constructor and Process.Start (dotnet#126076)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
1 parent b5c98ef commit 18a940b

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void Refresh() { }
160160
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
161161
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
162162
[System.Runtime.Versioning.SupportedOSPlatformAttribute("maccatalyst")] // this needs to come after the ios attribute due to limitations in the platform analyzer
163-
public static System.Diagnostics.Process Start(string fileName, string arguments) { throw null; }
163+
public static System.Diagnostics.Process Start(string fileName, string? arguments) { throw null; }
164164
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
165165
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
166166
[System.Runtime.Versioning.SupportedOSPlatformAttribute("maccatalyst")] // this needs to come after the ios attribute due to limitations in the platform analyzer
@@ -221,7 +221,7 @@ public sealed partial class ProcessStartInfo
221221
{
222222
public ProcessStartInfo() { }
223223
public ProcessStartInfo(string fileName) { }
224-
public ProcessStartInfo(string fileName, string arguments) { }
224+
public ProcessStartInfo(string fileName, string? arguments) { }
225225
public ProcessStartInfo(string fileName, System.Collections.Generic.IEnumerable<string> arguments) { }
226226
public System.Collections.ObjectModel.Collection<string> ArgumentList { get { throw null; } }
227227
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ public static Process Start(string fileName)
13131313
[UnsupportedOSPlatform("ios")]
13141314
[UnsupportedOSPlatform("tvos")]
13151315
[SupportedOSPlatform("maccatalyst")]
1316-
public static Process Start(string fileName, string arguments)
1316+
public static Process Start(string fileName, string? arguments)
13171317
{
13181318
// the underlying Start method can only return null on Windows platforms,
13191319
// when the ProcessStartInfo.UseShellExecute property is set to true.

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ProcessStartInfo(string fileName)
4949
/// Specifies the name of the application that is to be started, as well as a set
5050
/// of command line arguments to pass to the application.
5151
/// </devdoc>
52-
public ProcessStartInfo(string fileName, string arguments)
52+
public ProcessStartInfo(string fileName, string? arguments)
5353
{
5454
_fileName = fileName;
5555
_arguments = arguments;

src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,17 @@ public void TestArgumentsProperty()
448448
Assert.Equal("-arg3 -arg4", psi.Arguments);
449449
}
450450

451+
[Fact]
452+
public void TestArgumentsNullProperty()
453+
{
454+
string? args = null;
455+
ProcessStartInfo psi = new ProcessStartInfo("filename", args);
456+
Assert.Equal(string.Empty, psi.Arguments);
457+
458+
psi.Arguments = null;
459+
Assert.Equal(string.Empty, psi.Arguments);
460+
}
461+
451462
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported)), InlineData(true), InlineData(false)]
452463
public void TestCreateNoWindowProperty(bool value)
453464
{

0 commit comments

Comments
 (0)