{"record":{"id":"03b156c9a0a2249f","repo":"RicoSuter/NSwag","slug":"runtime-runtime-n-stacktrace","errorCode":null,"errorMessage":"Runtime: \" + Runtime + \"\\n\" + stackTrace","messagePattern":"Runtime: \" \\+ Runtime \\+ \"\\\\n\" \\+ stackTrace","errorType":"exception","errorClass":"CommandLineException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Commands/NSwagDocument.cs","lineNumber":221,"sourceCode":"                if (stackTraceStart < 0)\n                {\n                    stackTraceStart = error.IndexOf(\"   at \", StringComparison.Ordinal);\n                }\n\n                var message = stackTraceStart > 0 ? error.Substring(0, stackTraceStart) : error;\n                var stackTrace = stackTraceStart > 0 ? error.Substring(stackTraceStart) : \"\";\n\n                if (message.Contains(\"Could not load type\"))\n                {\n                    message += \"Try running the document in another runtime, e.g. /runtime:NetCore20\";\n                }\n\n                if (message.Contains(\"The system cannot find the file specified\"))\n                {\n                    message += \"Check if .NET Core is installed and 'dotnet' is globally available.\";\n                }\n\n                throw new CommandLineException(message, \"Runtime: \" + Runtime + \"\\n\" + stackTrace);\n            }\n\n            return output;\n        }\n\n        private string GetDocumentDirectory()\n        {\n            var absoluteDocumentPath = PathUtilities.MakeAbsolutePath(Path, Directory.GetCurrentDirectory());\n            return System.IO.Path.GetDirectoryName(absoluteDocumentPath);\n        }\n\n#pragma warning disable CA1822\n        private string GetArgumentsPrefix()\n#pragma warning restore CA1822\n        {\n#if NET462\n\n            var runtime = Runtime != Runtime.Default ? Runtime : RuntimeUtilities.CurrentRuntime;","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Commands/NSwagDocument.cs#L203-L239","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (nswag.json)\n\"runtime\": \"NetCore21\"\n// after\n\"runtime\": \"Net80\" // or install the .NET Core 2.1 runtime","handlingStrategy":"try-catch","validationCode":"var dotnet = RunAndCapture(\"dotnet\", \"--version\"); // fail early if dotnet is missing\nif (string.IsNullOrWhiteSpace(dotnet))\n    throw new InvalidOperationException(\"'dotnet' is not on PATH; install the required .NET runtime.\");","typeGuard":null,"tryCatchPattern":"try { var output = await document.StartCommandLineProcessAsync(process, arguments); }\ncatch (CommandLineException ex)\n{ log.Error($\"NSwag subprocess failed (runtime {document.Runtime}): {ex.Message} \\n{ex.StackTrace}\"); throw; }","preventionTips":["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."],"tags":["process","runtime","dotnet","cli"],"backgroundTag":"http-request-failed","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}