question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error generating code for AppCenter API (System.InvalidOperationException: The properties 'id', 'name' are defined multiple times.)

See original GitHub issue

Am trying to generate a C# rest client for the Visual Studio AppCenter API (the API itself can be browsed at: https://openapi.appcenter.ms/#/) as there’s no official C#/.NET client.

Command line (this is called in Visual Studio when the build command is invoked): C:\Users\buildrunner\.nuget\packages\nswag.msbuild\13.0.5\build\../tools/Win/NSwag.exe openapi2csclient /className:AppCenterRestApi /namespace:AppCenterApi /input:C:\Users\buildrunner\source\repos\AppCenterRestClient\swagger.json /output:C:\Users\buildrunner\source\repos\AppCenterRestClient\obj\swaggerClient.cs

JSON input file is from https://openapi.appcenter.ms/#/, or viewed directly via https://api.appcenter.ms/preview/swagger.json

Stack trace:

System.InvalidOperationException: The properties 'id', 'name' are defined multiple times.
   at NJsonSchema.JsonSchema.get_ActualProperties()
   at NJsonSchema.CodeGeneration.CSharp.Models.ClassTemplateModel..ctor(String typeName, CSharpGeneratorSettings settings, CSharpTypeResolver resolver, JsonSchema schema, Object rootObject)
   at NJsonSchema.CodeGeneration.CSharp.CSharpGenerator.GenerateClass(JsonSchema schema, String typeName)
   at NJsonSchema.CodeGeneration.GeneratorBase.GenerateTypes()
   at NJsonSchema.CodeGeneration.CSharp.CSharpGenerator.GenerateTypes()
   at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateFile(ClientGeneratorOutputType outputType)
   at NSwag.Commands.CodeGeneration.SwaggerToCSharpClientCommand.<<RunAsync>b__83_0>d.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.CodeGeneration.SwaggerToCSharpClientCommand.<RunAsync>d__83.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.CodeGeneration.SwaggerToCSharpClientCommand.<RunAsync>d__82.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 NConsole.CommandLineProcessor.Process(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.Process(String[] args)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mamiftcommented, Apr 16, 2021

You have to put it on the class in your code and NSwag.exe picks this up… there is a global configuration where you can flatten everything without touching the code - not sure this is what you want though

OK but my input is a JSON schema, as I’m trying to generate C# code for the REST client. The command I’m trying to run is NSwag.exe openapi2csclient /className:AppCenterRestApi /namespace:AppCenterApi /input:C:\Users\mamift\source\repos\AppCenterRestClient\swagger.json /output:C:\Users\mamift\source\repos\AppCenterRestClient\swaggerClient.cs

Is there any interface in the command line that can be used to pass that flag to flatten the classes? When I go NSwag.exe help openapi2csclient I cannot find a flag that refers to class flattening.

0reactions
PatrickMatthiesencommented, Jun 15, 2023

I’m having a similar issue trying to make a client using the dotnet-openapi tool, it complains about “fireRate” existing multiple times. Though loading the spec using the swagger editor I find no issues with the file.

OpenApi spec Url: https://docs.warframestat.us/openapi.json

System.InvalidOperationException: The properties 'fireRate' are defined multiple times.
     at NJsonSchema.JsonSchema.get_ActualProperties()
     at NJsonSchema.CodeGeneration.CSharp.Models.ClassTemplateModel..ctor(String typeName, CSharpGeneratorSettings sett
  ings, CSharpTypeResolver resolver, JsonSchema schema, Object rootObject)
     at NJsonSchema.CodeGeneration.CSharp.CSharpGenerator.GenerateClass(JsonSchema schema, String typeName)
     at NJsonSchema.CodeGeneration.CSharp.CSharpGenerator.GenerateType(JsonSchema schema, String typeNameHint)
     at NJsonSchema.CodeGeneration.GeneratorBase.GenerateTypes()
     at NJsonSchema.CodeGeneration.CSharp.CSharpGenerator.GenerateTypes()
     at NSwag.CodeGeneration.CSharp.CSharpGeneratorBase.GenerateDtoTypes() in /_/src/NSwag.CodeGeneration.CSharp/CSharp
  GeneratorBase.cs:line 106
     at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateFile(ClientGeneratorOutputType outputType) in /_/src/NSwag.C
  odeGeneration/ClientGeneratorBase.cs:line 75
     at NSwag.Commands.CodeGeneration.SwaggerToCSharpClientCommand.RunAsync() in /_/src/NSwag.Commands/Commands/CodeGen
  eration/OpenApiToCSharpClientCommand.cs:line 270
     at NSwag.Commands.CodeGeneration.SwaggerToCSharpClientCommand.RunAsync(CommandLineProcessor processor, IConsoleHos
  t host) in /_/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToCSharpClientCommand.cs:line 248
     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 61
Read more comments on GitHub >

github_iconTop Results From Across the Web

The method 'get' on path '/Site' is registered multiple times - ...
System.InvalidOperationException: The method 'get' on path '/Site' is registered multiple times. at NSwag.Generation.AspNetCore.
Read more >
Unable to compile Xamarin.Android project in VS 2022 ...
targets(106,5): error XAPRAS7009: System.InvalidOperationException: PE image does not have metadata. 1>C:\Program Files\dotnet\packs\Microsoft.
Read more >
Sitecore Experience Platform 8.0
This topic contains a glossary of Sitecore Experience Analytics terms, with short definitions. Asset. A piece of content, for example, a PDF file,...
Read more >
Monitoring Application Performance with Application Insights
Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms.
Read more >
Build a Sample Application with Microservices
In this lab we will go through a set of steps for building a sample application with multiple microservices. DevOps MPP Course Source....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found