Fix Process standard stream examples to avoid resource leaks and add ownership remarks#12659
Fix Process standard stream examples to avoid resource leaks and add ownership remarks#12659Copilot wants to merge 2 commits into
Conversation
…ownership remarks - Inline StandardOutput/StandardError stream access in examples to avoid undisposed StreamReader variables - Add IMPORTANT notes to StandardOutput, StandardError, and StandardInput documentation clarifying stream ownership and disposal responsibilities - Remove unused System.IO imports from updated snippets Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/6f53bd78-3ca0-40fb-8937-2ca2c5abfd3e Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
|
@adamsitnik, I think Copilot got a little too excited here and didn't understand the issue and technically the "fix" is worse. Instead of adding As I stated originally in the reporting issue, documentation fix is one option. But Copilot did demonstrate exactly how unaware developer would make a mistake (chaining and reading directly, without acknowledging having taken ownership). So, I'd re-evaluate the weird contract and consider to have But at minimum, for documentation purposes, Copilot should've created |
Process.StandardOutput/StandardErrorexamples assigned the stream to a local variable without disposing it, creating a resource leak. Documentation also lacked any explanation of stream ownership semantics.Snippet fixes
Inlined stream access to eliminate undisposed
StreamReader/StreamWritervariables:Applied to all three language variants (C#, VB, F#) for both
StandardOutputandStandardErrorexamples.Documentation remarks
Added
[!IMPORTANT]notes toStandardOutput,StandardError, andStandardInputinProcess.xmlclarifying:Process.Dispose()will not close itBeginOutputReadLine/BeginErrorReadLineretains process ownership and disposes on process disposal