title: ABP/Swashbuckle - Generating swagger docs using Swashbuckle CLI
body: <p>Using ABP Framework (3.3) and ASP.NET Core (3.1).</p>
  <p>I'm attempting to generate swagger.json using Swashbuckle.AspNetCore.Cli (<a href="https://github.com/domaindrivendev/Swashbuckle.AspNetCore#retrieve-swagger-directly-from-a-startup-assembly" rel="nofollow noreferrer">https://github.com/domaindrivendev/Swashbuckle.AspNetCore#retrieve-swagger-directly-from-a-startup-assembly</a>) after compiling the application, pointing to the compiled dll using the following command:</p>
  <p><code>dotnet swagger tofile --output &quot;C:\temp\swagger&quot; .\bin\Release\netcoreapp3.1\MyBin.dll v1</code></p>
  <p>It gives me the below exception:</p>
  <pre><code>Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'provider')
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceCollectionCommonExtensions.GetRequiredService[T](IServiceCollection services)
     at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
     at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
     at System.Lazy`1.CreateValue()
     at System.Lazy`1.get_Value()
     at Volo.Abp.AspNetCore.Mvc.AbpDataAnnotationAutoLocalizationMetadataDetailsProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
     at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultCompositeMetadataDetailsProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
     at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_DisplayMetadata()
     at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Order()
     at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.&lt;&gt;c.&lt;get_Properties&gt;b__78_0(ModelMetadata p)
     at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
     at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count)
     at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
     at System.Linq.OrderedEnumerable`1.ToList()
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at Microsoft.AspNetCore.Mvc.ModelBinding.ModelPropertyCollection..ctor(IEnumerable`1 properties)
     at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Properties()
     at Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadataProviderExtensions.GetMetadataForProperty(IModelMetadataProvider provider, Type containerType, String propertyName)
     at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.CreatePropertyModel(PropertyInfo propertyInfo)
     at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.OnProvidersExecuting(ApplicationModelProviderContext context)
     at Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory.CreateApplicationModel(IEnumerable`1 controllerTypes)
     at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
     at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
     at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
     at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
     at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.get_ActionDescriptors()
     at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups()
     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
     at Swashbuckle.AspNetCore.Cli.Program.&lt;&gt;c.&lt;Main&gt;b__0_3(IDictionary`2 namedArgs) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 72
     at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 68
     at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 68
     at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 111
  </code></pre>
  <p>I've tried also creating a public class as per the Swashbuckle docs, as we are using Autofac:</p>
  <pre><code>    public class SwaggerHostFactory
      {
          public static IHost CreateHost()
          {
              return Program.CreateHostBuilder(new string[0]).Build(); //Calls the same builder that's used to run the app
          }
      }
  </code></pre>
  <p>The intent is to allow running this in our pipelines to auto-generate ApiClient libraries.</p>
  <p>I'm at a bit of a loss as to how to resolve this. The swagger.json is generated at runtime perfectly fine?</p>
  <p>Any help appreciated!</p>