NSwag: Nswag 14 CLI /runtime argument not running with Net80

Runtime specified in nswag.json as “Net80”.

image

Not quite sure if it’s needed in both places, but did it to make sure.

Then run the Nswag CLI tool (npm i -g nswag@14) run command:

> nswag run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json

NSwag NPM CLI
NSwag command line tool for .NET Core Net70, toolchain v14.0.0.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\binaries\Net80

Executing file '..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json' with variables ''...
System.InvalidOperationException: The specified runtime in the document (Net80) differs from the current process runtime (Net70). Change the runtime with the '/runtime:Net80' parameter or run the file with the correct command line binary.
   at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 69
   at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 33
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 62node:child_process:965
    throw err;
    ^

Error: Command failed: dotnet "C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin/binaries/Net80/dotnet-nswag.dll" run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json
    at checkExecSyncError (node:child_process:890:11)
    at Object.execSync (node:child_process:962:15)
    at C:\Users\DylanvanderMerwe\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\nswag.js:64:27
    at ChildProcess.exithandler (node:child_process:414:7)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at ChildProcess._handle.onexit (node:internal/child_process:303:5) {
  status: 4294967295,
  signal: null,
  output: [ null, null, null ],
  pid: 73448,
  stdout: null,
  stderr: null
}

Alright then let’s set the /runtime parameter with the CLI:

> nswag run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json /runtime:Net80

NSwag NPM CLI
NSwag command line tool for .NET Core Net70, toolchain v14.0.0.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\binaries\Net80
NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net80]
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 62node:child_process:965
    throw err;
    ^

Error: Command failed: dotnet "C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin/binaries/Net80/dotnet-nswag.dll" run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json /runtime:Net80
    at checkExecSyncError (node:child_process:890:11)
    at Object.execSync (node:child_process:962:15)
    at C:\Users\DylanvanderMerwe\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\nswag.js:57:19
    at ChildProcess.exithandler (node:child_process:414:7)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at ChildProcess._handle.onexit (node:internal/child_process:303:5) {
  status: 4294967295,
  signal: null,
  output: [ null, null, null ],
  pid: 32788,
  stdout: null,
  stderr: null
}

The correct runtime is specified in the config file.

It seems like there is an issue with the CLI. Please advise how to get this working as after updating to net80 we cannot use nswag via the CLI to generate Typescript.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 17
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Removing passed runtime argument in nswag.cmd works for me.

@ECHO OFF
set args=%*

IF NOT "%args:/runtime:winx86=%" == "%args%" (
    "%~dp0/Win/nswag.x86.exe" %*
    GOTO end
)

IF NOT "%args:/runtime:net60=%" == "%args%" (
    dotnet "%~dp0/Net60/dotnet-nswag.dll" %*
    GOTO end
)

IF NOT "%args:/runtime:net70=%" == "%args%" (
-   dotnet "%~dp0/Net70/dotnet-nswag.dll" %*
+   dotnet "%~dp0/Net70/dotnet-nswag.dll" %args:/runtime:net70=%
    GOTO end
)

IF NOT "%args:/runtime:net80=%" == "%args%" (
    dotnet "%~dp0/Net80/dotnet-nswag.dll" %*
    GOTO end
)

"%~dp0/Win/nswag.exe" %*
:end

Still an issue in 14.0.8. Running from the command line without /runtime:Net80 tells you to add it. Running with it tells you to remove it.

nswag run file.nswag.json

NSwag command line tool for .NET 4.6.2+ WinX64, toolchain v14.0.8.0 (NJsonSchema v11.0.1.0 (Newtonsoft.Json v13.0.0.0))

Visit http://nswag.org/ for more information.

NSwag bin directory: C:\Program Files (x86)\Rico Suter\NSwagStudio\Win

Executing file ‘enviApi.nswag.json’ with variables ‘’…

System.InvalidOperationException: The specified runtime in the document (Net80) differs from the current process runtime (WinX64). Change the runtime with the ‘/runtime:Net80’ parameter or run the file with the correct command line binary.

at NSwag.Commands.Document.ExecuteDocumentCommand.<ExecuteDocumentAsync>d__9.MoveNext()

— End of stack trace from previous location where exception was thrown —

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at NSwag.Commands.Document.ExecuteDocumentCommand.<RunAsync>d__8.MoveNext()

— End of stack trace from previous location where exception was thrown —

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at NConsole.CommandLineProcessor.<ProcessSingleAsync>d__12.MoveNext()

— End of stack trace from previous location where exception was thrown —

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at NConsole.CommandLineProcessor.<ProcessAsync>d__11.MoveNext()

— End of stack trace from previous location where exception was thrown —

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at NSwag.Commands.NSwagCommandProcessor.<ProcessAsync>d__3.MoveNext()

nswag run file.nswag.json /runtime:Net80

NSwag command line tool for .NET Core Net80, toolchain v14.0.8.0 (NJsonSchema v11.0.1.0 (Newtonsoft.Json v13.0.0.0))

Visit http://nswag.org/ for more information.

NSwag bin directory: C:\Program Files (x86)\Rico Suter\NSwagStudio\Net80

NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net80]

at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)

at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)

at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in _/src/NSwag.Commands/NSwagCommandProcessor.cs:line 65

Renaming the file to file.nswag and then running this does work: nswag run /runtime:Net80

I’m still getting this issue with 14.0.1 when calling openapi2tsclient /runtime:Net80 /input:....OpenAPI.json

NSwag command line tool for .NET Core Net80, toolchain v14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
NSwag bin directory: /blabla/node_modules/nswag/bin/binaries/Net80
NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net80]

remove /runtime:Net80

Same here but had to remove the /runtime:Net60 argument in the nswag command nswag run client.nswag using version 14.0.1

Seems like the runtime argument in the cli is not used anymore?

NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net60]

for run command runtime is supported but only for default config files (so it will take default nswag.json or *.nswag files)

As mentioned in log, cmd is using Net70 instead of Net80 I think, #4680 should resolve this issue

Here’s how i got it to work bypassing the error ‘t_he specified runtime in the document (Net80) differs from the current process runtime…_’ using the cli version 14.2.0. My .net core Api is .NET core 8. However the cli is expecting .net core 9. After reviewing a bit the source code of the cli, i realized that the runtime inside the .nswag must be Net90. So i changed the runtime to Net90(e.g.:“runtime”: “Net90”) as displayed in the following image:

Image After this change i run my project in order to load in the browser and then i run the cli by,nswag run. The output.ts was succesfully got generated in my project root.