Skip to content

Fix DiagnosticsClient.WriteDump to handle dump paths with spaces on Windows#5593

Merged
steveisok merged 4 commits intomainfrom
copilot/fix-dump-creation-error
Apr 2, 2026
Merged

Fix DiagnosticsClient.WriteDump to handle dump paths with spaces on Windows#5593
steveisok merged 4 commits intomainfrom
copilot/fix-dump-creation-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 8, 2025

Summary

Fixes #5020 - DiagnosticsClient.WriteDump() now correctly handles dump file paths containing spaces on Windows.

Problem

When calling WriteDump() with a path containing spaces on Windows, the operation would fail with the error:

[createdump] The pid argument is no longer supported

This occurred because the runtime's createdump utility on Windows was parsing the unquoted path as multiple command-line arguments. For example, a path like C:\my dumps\dump.dmp would be split into C:\my and dumps\dump.dmp, causing the latter part to be misinterpreted as additional arguments.

This issue is specific to Windows due to how the runtime builds the command line for createdump. Linux and macOS do not have this problem.

Solution

The fix wraps the dump path in quotes before sending it to the runtime on Windows only:

  • Paths are now automatically quoted on Windows: C:\my dumps\dump.dmp"C:\my dumps\dump.dmp"
  • Logic prevents double-quoting if the path is already quoted (handles the workaround some users may have implemented)
  • Non-Windows platforms (Linux/macOS) are unaffected and paths are passed through unchanged

Changes

Modified the two CreateWriteDumpMessage method overloads in DiagnosticsClient.cs to:

  1. Check the platform using RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
  2. Quote the dump path before serialization only on Windows
  3. Check if the path is already quoted to avoid double-quoting
// Quote the path to handle spaces correctly in createdump on Windows only
// Only add quotes if the path is not already quoted
// This is only needed on Windows where the runtime builds the command line for createdump
string pathToUse = dumpPath;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
    pathToUse = dumpPath.StartsWith("\"") && dumpPath.EndsWith("\"") ? dumpPath : $"\"{dumpPath}\"";
}

Testing

Manually verified the quoting logic handles:

On Windows:

  • ✅ Paths without spaces: C:\dumps\dump.dmp"C:\dumps\dump.dmp"
  • ✅ Paths with spaces: C:\my dumps\dump.dmp"C:\my dumps\dump.dmp" (fixes the issue)
  • ✅ Already quoted paths: "C:\my dumps\dump.dmp""C:\my dumps\dump.dmp" (no double-quoting)

On Linux/macOS:

  • ✅ All paths are passed through unchanged (no quoting applied)

The fix is minimal, backward compatible, platform-specific, and addresses the reported issue while maintaining compatibility with the workaround mentioned in the issue.

[!WARNING]

Fixes #5020

Original prompt

This section details on the original issue you should resolve

<issue_title>Diagnostics client fails to create dump when path has spaces</issue_title>
<issue_description>### Description

.NET diagnostics client fails when path to dump file has spaces in it. This reproduces both on net8 and net9, and fails with error:

[createdump] The pid argument is no longer supported coming from here

It can be fixed by wrapping the path to extra "".

I am using the latest version of the client package.

Reproduction Steps

<!-- file DumpError.csproj -->
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.547301" />
  </ItemGroup>

</Project>
// file Program.cs
using Microsoft.Diagnostics.NETCore.Client;
using System.Diagnostics;

public static class Program
{
    public static int Main(string[] args)
    {
        if (args.Length > 0 && args[0] == "--hang")
        {
            Thread.Sleep(int.MaxValue);
        }

        var path = Path.Combine(AppContext.BaseDirectory, "DumpError.exe");
        Process? process = null;
        try
        {
            process = Process.Start(path, "--hang");
            var diagnosticClient = new DiagnosticsClient(process.Id);
            Thread.Sleep(1_000);
            diagnosticClient.WriteDump(DumpType.Full, $"{Path.Combine(AppContext.BaseDirectory, $"my dump with spaces {Stopwatch.GetTimestamp()}.dmp")}", logDumpGeneration: true);
        }
        finally
        {
            process?.Kill();
        }

        return 0;
    }
}

Expected behavior

Spaces are correctly escaped and my dump is written to disk.

Actual behavior

[createdump] The pid argument is no longer supported error is shown and dump is not written.

Regression?

No.

Known Workarounds

Add quotes around the path, or move to folder without spaces.

Configuration

Win 11, 8.0.110, but reproduces on latest net9 as well.

Other information

No response</issue_description>

<agent_instructions>See what you can do to support spaces in the path when generating a dump file calling WriteDump.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #5020

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 8, 2025 23:36
Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix diagnostics client dump creation with paths containing spaces Fix DiagnosticsClient.WriteDump to handle dump paths with spaces Oct 8, 2025
Copilot AI requested a review from steveisok October 8, 2025 23:41
@steveisok
Copy link
Copy Markdown
Member

@copilot from the comments on the issue this PR is linked to, the quote behavior was only needed on windows. The non-windows targets did not have this problem.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot from the comments on the issue this PR is linked to, the quote behavior was only needed on windows. The non-windows targets did not have this problem.

Updated the fix to apply quoting only on Windows. The path quoting is now wrapped in a RuntimeInformation.IsOSPlatform(OSPlatform.Windows) check, so Linux/macOS are unaffected. Commit: Updated in the latest commit above.

Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
Copilot AI changed the title Fix DiagnosticsClient.WriteDump to handle dump paths with spaces Fix DiagnosticsClient.WriteDump to handle dump paths with spaces on Windows Oct 9, 2025
@steveisok steveisok marked this pull request as ready for review October 15, 2025 19:36
@steveisok steveisok requested a review from a team as a code owner October 15, 2025 19:36
@steveisok steveisok enabled auto-merge (squash) October 16, 2025 11:55
@steveisok steveisok merged commit 455cd12 into main Apr 2, 2026
19 checks passed
hoyosjs added a commit that referenced this pull request Apr 2, 2026
Copilot aided release notes for user facing changes

---------------------------------------------------------------------

Breaking Changes

- COMPLUS_* environment variable references removed from SOS — use
DOTNET_* equivalents (#5714)
- !name2ee and !token2ee output is now less verbose; modules that don't
contain the requested type are no longer listed (#5719)

dotnet-dump / SOS

New features:

- Add -stat flag to !threadpool to summarize queued work items by type
(#5737)
 - Add sort-by-count option to !dumpheap (#5722)
- Add -noprogress flag to !dumpheap and !verifyheap to suppress progress
reporting (#5773)
- Add -all flag to DumpMT to show class details and method descriptors
in one command (#5701)
- !DumpStackObjects now finds objects correctly during stack overflow
scenarios on Linux (#5723)
- Warn when loading a dump not collected by createdump, as SOS commands
may produce incomplete results (#5720)
- SOS output is now captured correctly by LLDB Python scripts and tools
like lldb-dap (#5728)

Bug fixes:

 - Fix !u failing on IL stubs (#5726)
- Fix DumpIL showing a cryptic error on IL stubs — now explains IL is
unavailable (#5731)
- Fix clrstack -l displaying incorrect values for ushort locals ≥ 0x8000
(#5721)

dotnet-trace / collect-linux

- Enable callstack capture for .NET runtime events in collect-linux —
exception and GC stacks now include resolved frames (#5756)
- collect-linux --probe now gracefully handles unreachable processes
instead of throwing (#5705)
- Fix crash in collect-linux in environments without terminal cursor
support (#5771)
- Fix collect-linux throwing when stdin/stdout are redirected (e.g.
piped or scripted) (#5745)
- Fix terminal cursor not being restored after collect-linux exits
(#5747, #5707)

dotnet-counters

- Add --noAbbreviateValues option to monitor to display full-precision
values without K/M/G abbreviation (#5734)

Diagnostic Tools (general)

- Fix WriteDump failing when the dump path contains spaces on Windows
(#5593)
- Diagnostic tools now work from sidecar containers — dotnet-trace,
dotnet-counters, dotnet-stack, and dotnet-dump can attach to processes
in other containers without manual socket configuration (#5735)

Libraries

- Improved symbol resolution performance by caching failed lookups
(#5729)
- Symbol server key generation now supports ELF binaries from custom
toolchains (#5736)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagnostics client fails to create dump when path has spaces

3 participants