diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs index dfd1c7f497..d1ce07beed 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs @@ -698,7 +698,15 @@ private static IpcMessage CreateWriteDumpMessage(DumpType dumpType, string dumpP throw new ArgumentNullException($"{nameof(dumpPath)} required"); } - byte[] payload = SerializePayload(dumpPath, (uint)dumpType, logDumpGeneration); + // 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}\""; + } + byte[] payload = SerializePayload(pathToUse, (uint)dumpType, logDumpGeneration); return new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump, payload); } @@ -709,7 +717,15 @@ private static IpcMessage CreateWriteDumpMessage(DumpCommandId command, DumpType throw new ArgumentNullException($"{nameof(dumpPath)} required"); } - byte[] payload = SerializePayload(dumpPath, (uint)dumpType, (uint)flags); + // 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}\""; + } + byte[] payload = SerializePayload(pathToUse, (uint)dumpType, (uint)flags); return new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)command, payload); }