Process.Start with RedirectStandardOutput fails with System.PlatformNotSupportedException in .NET 9 #113450
Labels
area-System.Diagnostics.Process
needs-author-action
An issue or pull request that requires more info or actions from the author.
untriaged
New issue has not been triaged by the area owner
Description
I've inherited some code that creates a new process with Process.Start() which redirects its stdout to report benchmark results back to the parent process. The second process uses loads an assembly through reflection. The target assembly calls into another library that uses
System.Management
and results in an exception:System.PlatformNotSupportedException: 'System.Management currently is only supported for Windows desktop applications.'
I believe I've found a couple bugs that, loosely(?), relate to this: #17938 #28005
It seems like the "simple" fix is to set
UseShellExecute
to true, however, that doesn't work in this case since I'm also redirecting IO streams:The Process object must have the UseShellExecute property set to false in order to redirect IO streams.
Although UseShellExecute defaults to true in .net framework, I'm assuming that it might disable it if io redirect is being used? So, maybe there is something else that needs to be set?
Hopefully this makes sense. If not, I'll try to clarify further.
Reproduction Steps
Create an application that uses Process.Start to run a second application. The second application would take some arguments such as the target assembly to load and which method and arguments to call.
The second application then uses reflection to call code in the target assembly which contains something platform specific.
In the first application:
In the second application:
Something simple like this, I think, should work for the library:
Expected behavior
Executes correctly
Actual behavior
It throws this exception: System.PlatformNotSupportedException
Regression?
This works when targeting net472.
Known Workarounds
No response
Configuration
.NET 9.0
Windows 11
x64
I don't think it is specific to this configuration
Other information
No response
The text was updated successfully, but these errors were encountered: