Nswag: Failed to generate client when using NetCore30 Project as source

Created on 8 Oct 2019  路  1Comment  路  Source: RicoSuter/NSwag

NSwagStudio, v13.1.2.0

In Program.cs of API project:

public class Program
{
  public static void Main(string[] args)
  {
    CreateWebHostBuilder(args).Build().Run();
  }

  public static IHostBuilder CreateWebHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
      .ConfigureWebHostDefaults(builder =>
      {
        builder.ConfigureKestrel(opts =>
          {
            // ...
          })
          .UseStartup<Startup>();
      })
      .ConfigureServices(services =>
      {
        services.AddHostedService<SearchIndexingService>();
      });
}

In NSwagStudio:

  • Runtime NetCore30
  • ASP.NET Core via API Explorer
  • Project

Generation:

  • TypeScript Client
  • Default settings

Generate Outputs throws following:

Launcher directory: C:\Program Files (x86)\Rico Suter\NSwagStudio\NetCore30
System.InvalidOperationException: Swagger generation failed with non-zero exit code '1'.

Runtime: NetCore30
   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiCommand.cs:line 221
   at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocumentBase.cs:line 279
   at NSwag.Commands.NSwagDocument.ExecuteAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocument.cs:line 81
   at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 86
   at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 32
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.Process(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\projects\nswag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 56

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidCastException: Unable to cast object of type 'Microsoft.Extensions.Hosting.HostBuilder' to type 'Microsoft.AspNetCore.Hosting.IWebHostBuilder'.
   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint.GetServiceProvider(String applicationName) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs:line 67
   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint.Process(String commandContent, String outputFile, String applicationName) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs:line 26
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at NSwag.AspNetCore.Launcher.Program.Main(String[] args) in C:\projects\nswag\src\NSwag.AspNetCore.Launcher\Program.cs:line 170

Most helpful comment

Ok, just need to rename 'CreateWebHostBuilder' to 'CreateHostBuilder' and rebuild the project.

>All comments

Ok, just need to rename 'CreateWebHostBuilder' to 'CreateHostBuilder' and rebuild the project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Peter554 picture Peter554  路  3Comments

akamyshanov picture akamyshanov  路  4Comments

Zshazz picture Zshazz  路  4Comments

saephraim picture saephraim  路  3Comments

Rui90 picture Rui90  路  3Comments