RicoSuter/NSwag · error · CommandLineException
Runtime: " + Runtime + "\n" + stackTrace
Error message
Runtime: " + Runtime + "\n" + stackTrace
What it means
NSwagDocument.StartCommandLineProcessAsync launches an external process (e.g. a second NSwag/dotnet process for a different runtime) and throws CommandLineException when the process exits with an error, attaching the Runtime and its stack trace. If stderr contains 'The system cannot find the file specified', a hint about installing .NET Core / dotnet on PATH is appended.
Solutions
- Install the .NET Core SDK/runtime matching the document's Runtime setting and ensure 'dotnet' is on PATH ('dotnet --version').
- Change the document's 'runtime' property to a runtime available on the machine (e.g. WinX64 or Net80).
- Read the attached stack trace / inner message to find the actual process failure (e.g. missing commands DLL) and fix that underlying issue.
Example fix
// before (nswag.json) "runtime": "NetCore21" // after "runtime": "Net80" // or install the .NET Core 2.1 runtime
Defensive patterns
Strategy: try-catch
Validate before calling
var dotnet = RunAndCapture("dotnet", "--version"); // fail early if dotnet is missing
if (string.IsNullOrWhiteSpace(dotnet))
throw new InvalidOperationException("'dotnet' is not on PATH; install the required .NET runtime."); Try / catch
try { var output = await document.StartCommandLineProcessAsync(process, arguments); }
catch (CommandLineException ex)
{ log.Error($"NSwag subprocess failed (runtime {document.Runtime}): {ex.Message} \n{ex.StackTrace}"); throw; } Prevention
- Install the .NET runtime matching the document's 'runtime' property.
- Keep 'runtime' set to a runtime available on every machine/CI agent that runs the document.
- Verify 'dotnet --version' works in the execution environment.
- Capture and log the CommandLineException stack trace for the real failure.
When it happens
Trigger: The spawned process (dotnet/hosts run for a document targeting a different Runtime) fails or is missing: non-zero exit, 'dotnet' not on PATH, or the target runtime/host executable cannot be found.
Common situations: Documents with runtime NetCore21/NetCore50 etc. executed on a machine where that .NET Core runtime or 'dotnet' CLI is not installed; PATH problems in CI or services; Windows 'cannot find the file specified' because dotnet.exe is absent.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Project outputs could not be located in
- Unable to retrieve project metadata. Ensure it's an…
- Unknown error
- The specified runtime in the document
- The ouput of is a 32-bit application and requires…
AI-assisted analysis of RicoSuter/NSwag@63daf8fcc3 (2026-09-14).
Data as JSON: /api/errors/03b156c9a0a2249f.
Report an issue: GitHub.
Appendix: source
Thrown at src/NSwag.Commands/NSwagDocument.cs:221
if (stackTraceStart < 0)
{
stackTraceStart = error.IndexOf(" at ", StringComparison.Ordinal);
}
var message = stackTraceStart > 0 ? error.Substring(0, stackTraceStart) : error;
var stackTrace = stackTraceStart > 0 ? error.Substring(stackTraceStart) : "";
if (message.Contains("Could not load type"))
{
message += "Try running the document in another runtime, e.g. /runtime:NetCore20";
}
if (message.Contains("The system cannot find the file specified"))
{
message += "Check if .NET Core is installed and 'dotnet' is globally available.";
}
throw new CommandLineException(message, "Runtime: " + Runtime + "\n" + stackTrace);
}
return output;
}
private string GetDocumentDirectory()
{
var absoluteDocumentPath = PathUtilities.MakeAbsolutePath(Path, Directory.GetCurrentDirectory());
return System.IO.Path.GetDirectoryName(absoluteDocumentPath);
}
#pragma warning disable CA1822
private string GetArgumentsPrefix()
#pragma warning restore CA1822
{
#if NET462
var runtime = Runtime != Runtime.Default ? Runtime : RuntimeUtilities.CurrentRuntime;View on GitHub (pinned to 63daf8fcc3)