Skip to content

Generic startup issue #35256

@Andrey26

Description

@Andrey26

Issue:
When attempting to execute dotnet swagger tofile on dll with generic Startup class if fails to locate it.
I do not think that It is Swashbuckle library issue because .NET code fails to locate dll.

Reproduction scenario:

  1. From VS create a new ASP.NET Core Web Application. You can select ASP.NET Core Web API to have request and working API.
    image
  2. In Startup.cs, rewrite Startup to Startup<T>. Therefore in Program.cs, rewrite
webBuilder.UseStartup();

to (for example)

webBuilder.UseStartup<Startup<int>>();
  1. From cmd execute dotnet new tool-manifest in root folder of the project
  2. From cmd execute dotnet tool install --local --version ${​​​​swaggerVersion}​​​​ Swashbuckle.AspNetCore.Cli
    where ${​​​​swaggerVersion}​​​​ - is a version of Swashbuckle.AspNetCore.Swagger.dll located together with .dll
  3. From cmd execute dotnet tool restore
  4. From cmd execute dotnet swagger tofile --output <json documentation file name to generate> <full path to .dll> <version of Web Service API>

Result:

Unhandled exception. System.InvalidOperationException: A type named 'StartupProduction' or 'Startup' could not be found in assembly 'WebApplication1'.
   at Microsoft.AspNetCore.Hosting.StartupLoader.FindStartupType(String startupAssemblyName, String environmentName)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.<>c__DisplayClass14_2.<BuildCommonServices>b__2(IServiceProvider _)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.WebHost.EnsureStartup()
   at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()

Expected:
Swagger JSON/YAML succesfully written to <file path>

Assumption:
Called code only checks with Startup name and name of generic class will be different.

var startupNameWithoutEnv = "Startup";

throw new InvalidOperationException(String.Format("A type named '{0}' or '{1}' could not be found in assembly '{2}'.",

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedaffected-very-fewThis issue impacts very few customersarea-hostingIncludes Hostingarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsseverity-nice-to-haveThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions