RicoSuter/NSwag · error · Error
Unknown error
Error message
Unknown error
What it means
nswag.js runs 'dotnet --info' (spawnSync) to detect the installed .NET Core version before launching the NSwag command host. If the spawn itself failed it rethrows that error; if dotnet ran but exited non-zero with an empty stderr, the script throws new Error("Unknown error"). This means the .NET runtime probe failed without a diagnostic message.
Solutions
- Run 'dotnet --info' manually in the same shell to see the real failure and fix the .NET SDK installation (reinstall from https://dotnet.microsoft.com).
- Ensure the dotnet executable is on PATH and functional for the user running nswag.
- In CI, use a setup step (e.g. actions/setup-dotnet) to install a supported .NET Core SDK before running nswag.
- Check for a global.json pinning an SDK version that is not installed, and remove or correct it.
- Upgrade the @nswag/npm package so its supportedCoreVersions list matches your installed .NET version, avoiding the related 'not supported' exit path.
Defensive patterns
Strategy: try-catch
Validate before calling
// Before invoking nswag CLI, probe dotnet yourself
const { spawnSync } = require('child_process');
const r = spawnSync('dotnet', ['--info'], { encoding: 'utf8' });
if (r.error || r.status !== 0) {
console.error('dotnet CLI is broken or missing; install the .NET SDK first');
process.exit(1);
} Type guard
function isDotnetAvailable() {
const r = require('child_process').spawnSync('dotnet', ['--info'], { encoding: 'utf8' });
return !r.error && r.status === 0;
} Try / catch
try {
execSync('npx nswag run nswag.json');
} catch (err) {
if (String(err.message).includes('Unknown error')) {
console.error('nswag failed to probe dotnet; verify "dotnet --info" works manually');
}
process.exit(1);
} Prevention
- Install and verify the .NET SDK ('dotnet --info' exits 0) in every environment that runs nswag.
- In CI, add an official setup-dotnet step before running nswag.
- Keep @nswag/npm updated so its supported .NET version list matches your SDK.
- Check global.json does not pin an SDK version that is not installed.
When it happens
Trigger: Running the nswag npm CLI on a machine where 'dotnet --info' exits non-zero (broken or partially uninstalled .NET SDK, corrupted installation, permission issues), where stderr is empty so no better message can be surfaced.
Common situations: CI containers without the .NET SDK installed or with only the runtime; dotnet on PATH but a broken multi-level-lookup/globaljson setup; antivirus or permissions killing dotnet; incompatible SDK version left after an upgrade; PATH pointing to a shim that fails.
Related errors
- Project outputs could not be located in
- Unable to retrieve project metadata. Ensure it's an…
- Runtime: " + Runtime + "\n" + stackTrace
- 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/80b32d207154563a.
Report an issue: GitHub.
Appendix: source
Thrown at src/NSwag.Npm/bin/nswag.js:96
else if (runtimeIndices.length === 1) {
args.splice(runtimeIndices[0], 1);
}
if (runtimeValue) {
if (runtimeValue.toLowerCase() === "netcore") {
// detect latest installed NetCore Version
console.log("Trying to detect latest installed NetCore Version.");
var infoCmd = "dotnet";
var infoArgs = ["--version"];
try {
var result = c.spawnSync(infoCmd, infoArgs, { encoding: 'utf8' });
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(result.stderr ? result.stderr.toString() : "Unknown error");
}
var coreVersion = result.stdout.trim();
const version = supportedCoreVersions.find(v => coreVersion.startsWith(v.ver));
if (!version) {
console.error("Error: Detected .NET Core version '" + coreVersion + "' is not supported.");
process.exit(1);
}
console.log("Using supported .NET Core version: " + version.dir);
runtimeValue = version.dir;
} catch (error) {
console.error("Error: Could not detect .NET Core version.");
console.debug(error);
process.exit(1);
}
}
if (!runtimeValue.toLowerCase().startsWith("win")) {
const isSupported = supportedCoreVersions.some(v => v.dir.toLowerCase() === runtimeValue.toLowerCase());View on GitHub (pinned to 63daf8fcc3)