NSwag: Q: What are the rules to use nswag to avoid exceptions

Hello, I have been using nswag from the command line for some time now. Today, out of a sudden, I started getting this error:

System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at NSwag.CodeGeneration.TypeScript.Templates.RequestBodyTemplate.TransformText() in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration.TypeScript\Templates\RequestBodyTemplate.tt:line 2
   at NSwag.CodeGeneration.TypeScript.Templates.AngularClientTemplate.TransformText() in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration.TypeScript\Templates\AngularClientTemplate.tt:line
50
   at NSwag.CodeGeneration.TypeScript.Templates.AngularClientTemplate.Render() in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration.TypeScript\Templates\AngularClientTemplate.Extensions.cs:l
ine 18
   at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateFile(SwaggerDocument document, ClientGeneratorOutputType type) in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\ClientGeneratorBa
se.cs:line 90
   at NSwag.Commands.SwaggerToTypeScriptClientCommand.<<RunAsync>b__100_0>d.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\SwaggerToTypeScriptClientCommand.cs:line 265
--- 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.SwaggerToTypeScriptClientCommand.<RunAsync>d__100.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\SwaggerToTypeScriptClientCommand.cs:line 256
--- 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.SwaggerToTypeScriptClientCommand.<RunAsync>d__99.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\SwaggerToTypeScriptClientCommand.cs:line 249
--- 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.NSwagDocumentBase.<ExecuteAsync>d__28.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\NSwagDocumentBase.cs:line 187
--- 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.ExecuteDocumentCommandBase.<ExecuteDocumentAsync>d__5.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommandBase.cs:
line 52
--- 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.ExecuteDocumentCommandBase.<RunAsync>d__4.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommandBase.cs:line 39
--- 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() in C:\projects\nconsole\src\NConsole\CommandLineProcessor.cs:line 139
--- 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.<ProcessAsync>d__11.MoveNext() in C:\projects\nconsole\src\NConsole\CommandLineProcessor.cs:line 107
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\Data\Projects\NSwag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 59
---> (Inner Exception #0) System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at NSwag.CodeGeneration.TypeScript.Templates.RequestBodyTemplate.TransformText() in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration.TypeScript\Templates\RequestBodyTemplate.tt:line 2
   at NSwag.CodeGeneration.TypeScript.Templates.AngularClientTemplate.TransformText() in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration.TypeScript\Templates\AngularClientTemplate.tt:line
50
   at NSwag.CodeGeneration.TypeScript.Templates.AngularClientTemplate.Render() in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration.TypeScript\Templates\AngularClientTemplate.Extensions.cs:l
ine 18
   at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateFile(SwaggerDocument document, ClientGeneratorOutputType type) in C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\ClientGeneratorBa
se.cs:line 90
   at NSwag.Commands.SwaggerToTypeScriptClientCommand.<<RunAsync>b__100_0>d.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\SwaggerToTypeScriptClientCommand.cs:line 265
--- 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.SwaggerToTypeScriptClientCommand.<RunAsync>d__100.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\SwaggerToTypeScriptClientCommand.cs:line 256
--- 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.SwaggerToTypeScriptClientCommand.<RunAsync>d__99.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\SwaggerToTypeScriptClientCommand.cs:line 249
--- 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.NSwagDocumentBase.<ExecuteAsync>d__28.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\NSwagDocumentBase.cs:line 187
--- 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.ExecuteDocumentCommandBase.<ExecuteDocumentAsync>d__5.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommandBase.cs:
line 52
--- 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.ExecuteDocumentCommandBase.<RunAsync>d__4.MoveNext() in C:\Data\Projects\NSwag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommandBase.cs:line 39
--- 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() in C:\projects\nconsole\src\NConsole\CommandLineProcessor.cs:line 139
--- 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.<ProcessAsync>d__11.MoveNext() in C:\projects\nconsole\src\NConsole\CommandLineProcessor.cs:line 107<---
child_process.js:524
    throw err;
    ^

Error: Command failed: "D:\Workspace\...\node_modules\nswag\bin/binaries/full/nswag.exe" run
    at checkExecSyncError (child_process.js:481:13)
    at Object.execSync (child_process.js:521:13)
    at Object.<anonymous> (D:\Workspace\...\node_modules\nswag\bin\nswag.js:27:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)

I looked thoroughly in my code and I cannot find any duplicate method names in my controllers.

Is there another reason for such an exception to happen? What if 2 different method names but with the same input type, does that cause any problem?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Closed because it is a problem with Swashbuckle.

Thanks a lot. I will give it a try.

I think the url is the same (you canconfigure it) - the produced spec may differ (eg only one body param) but should be the same…

I see, you are using Swashbuckle to generate the swagger spec (and not NSwag). Somehow Swashbuckle generates two body params. You have to check its documentation or try NSwag’s swagger middleware (https://github.com/RSuter/NSwag/wiki/Middlewares)