Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: System.InvalidOperationException: A type named 'StartupProduction' or 'Startup' could not be found in assembly #3082

Open
MitchellW-DWL opened this issue Sep 26, 2024 · 4 comments
Labels
bug needs-repro A minimal reproducible example is needed

Comments

@MitchellW-DWL
Copy link

Describe the bug

Have been following #2168 and have tried all the described solutions there, running locally this works fine, running in PR checks it works fine, but then when running a deploy this breaks.

I'm on .net8 using swashbuckle 6.5.0 (Have tried with original version 6.2.3 and newest 6.8.0 too) it seemed to happen somewhat intermittently in the past but retrying the workflow would eventually get it through however now it's failing continuously.

`dotnet-tools.json`

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "swashbuckle.aspnetcore.cli": {
      "version": "6.5.0",
      "commands": [
        "swagger"
      ]
    }
  }
}

csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="DWL.Lib.Auth" Version="8.0.0-beta-10902437656" />
        <PackageReference Include="Mapster" Version="7.3.0" />
        <PackageReference Include="Mapster.DependencyInjection" Version="1.0.0" />
        <PackageReference Include="Serilog" Version="3.0.0-dev-02028" />
        <PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
        <PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
        <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
        <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
        <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Speechy.Service\Speechy.Service.csproj" />
    </ItemGroup>

    <ItemGroup>
      <Content Include=".config\dotnet-tools.json" />
    </ItemGroup>

    <Target Name="PostBuild" AfterTargets="PostBuildEvent">
        <Exec Command="dotnet tool restore" />
        <Exec Command="dotnet swagger tofile --output api.json $(OutputPath)\$(AssemblyName).dll v1" />
    </Target>
    
</Project>

Action build step

    - name: 🔨 Build
      run: dotnet build --no-restore -c Release
      env:
        API_IMPORT_DLL: 'Speechy/Speechy/Speechy.WebApi/bin/Release/net8.0/Speechy.WebApi.dll'
        SWASHBUCKLE_ASPNET_CORE_CLI_PACKAGE_VERSION: 6.5.0
        API_IMPORT_VERSION: v1
        CONFIGURATION: Release

Only difference between the PR check that works building the project and generating swagger json that I can discern is one is production, other is not but building in production locally works fine.

Expected behavior

Get a swagger openapi json spec

Actual behavior

Exception thrown

Steps to reproduce

No response

Exception(s) (if any)

Unhandled exception. System.InvalidOperationException: A type named 'StartupProduction' or 'Startup' could not be found in assembly 'Speechy.WebApi'.
     at Microsoft.AspNetCore.Hosting.StartupLoader.FindStartupType(String startupAssemblyName, String environmentName)
     at Microsoft.AspNetCore.Hosting.WebHostBuilder.ScanAssemblyAndRegisterStartup(ServiceCollection services, String startupAssemblyName)
  --- End of stack trace from previous location ---
     at Microsoft.AspNetCore.Hosting.WebHostBuilder.<>c__DisplayClass15_1.<ScanAssemblyAndRegisterStartup>b__1(IServiceProvider _)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, 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.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
     at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
     at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
     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()
     at Swashbuckle.AspNetCore.Cli.Program.GetServiceProvider(Assembly startupAssembly) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 145
     at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__0_4(IDictionary`2 namedArgs) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 82
     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 59
     at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 121
/home/runner/work/Speechy/Speechy/Speechy.WebApi/Speechy.WebApi.csproj(59,9): error MSB[30](https://github.com/dwlgit/Speechy/actions/runs/11048775286/job/30692886141#step:6:31)73: The command "dotnet swagger tofile --output api.json bin/Release/net8.0//Speechy.WebApi.dll v1" exited with code 134.

Swashbuckle.AspNetCore version

6.2.3, 6.4.0, 6.5.0, 6.8.0

.NET Version

.net8.0

Anything else?

Have been looking at all the following
#2168
Tried having a blank appsettings.Production.json file but still threw same error along with the different suggested versions

Have followed
https://stackoverflow.com/questions/78406014/system-invalidoperationexception-a-type-named-startupproduction-or-startup
Trying the suggest env vars for the step, but inclusion of them didnt seem to work and confirmed the file path is correct (Worth noting I only tried adding these after it started failing as didnt need them before that point)

Please let me know if there's anything else I can provide

@MitchellW-DWL
Copy link
Author

@martincostello Here's your new issue 👍

@martincostello
Copy link
Collaborator

Please provide a minimal reproducible example as a GitHub repository that demonstrates the issue you're experiencing so we can look into this further.

Support for Minimal APIs has been working in general for others, so I feel that this issue is something specific to how your project is set up (given how the exception isn't coming from our code).

We need something we can actually debug to look into to get towards any kind of resolution.

As a starting point, using the latest version will be a step forward you'll need as versions since 6.7.0 target net8.0 and also contain other bug fixes related to the CLI.

@martincostello martincostello added the needs-repro A minimal reproducible example is needed label Sep 26, 2024
@MitchellW-DWL
Copy link
Author

Support for Minimal APIs has been working in general for others, so I feel that this issue is something specific to how your project is set up (given how the exception isn't coming from our code).

Yeah this project doesn't use the minimal hosting - I'll try to find some time to replicate the issue but given it's intermittent it might be a struggle as the last instance I setup worked with no differences I could discern

@DenKn
Copy link

DenKn commented Oct 7, 2024

I have no Minimal API in my project.
But I've got the same issue

Swashbuckle.AspNetCore version - 6.8.1

.NET Version - .net8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-repro A minimal reproducible example is needed
Projects
None yet
Development

No branches or pull requests

3 participants