Skip to content

Application using Request Delegate Generator fails to start with KeyNotFoundException #48379

Closed
@martincostello

Description

@martincostello

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Enabling the Request Delegate Generator on an existing application of mine is causing the application to fail to start due to a KeyNotFoundException being thrown.

There appears to be an issue with something in the generated code which I think is for this endpoint.

Expected Behavior

The application runs the same as when the Request Delegate Generator is not enabled.

Steps To Reproduce

  1. Clone martincostello/adventofcode@daf9193
  2. Run build.ps1

Exceptions (if any)

2023-05-23T10:56:13.4242935Z �[39;49m�[31m  Error Message:
2023-05-23T10:56:13.4245412Z �[39;49m�[39;49m�[31m   System.Collections.Generic.KeyNotFoundException : The given key '(/_/src/AdventOfCode.Site/Program.cs, 125)' was not present in the dictionary.
2023-05-23T10:56:13.4247192Z �[39;49m�[39;49m�[31m  Stack Trace:
2023-05-23T10:56:13.4249132Z �[39;49m�[39;49m�[31m     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
2023-05-23T10:56:13.4251480Z    at Microsoft.AspNetCore.Http.Generated.<GeneratedRouteBuilderExtensions_g>FB49A76E00958A78ED8A3DC031D4149080B37ED6EB129C512F9112A3DB80F087D__GeneratedRouteBuilderExtensionsCore.MapCore(IEndpointRouteBuilder routes, String pattern, Delegate handler, IEnumerable`1 httpMethods, String filePath, Int32 lineNumber) in /_/src/AdventOfCode.Site/Microsoft.AspNetCore.Http.RequestDelegateGenerator/Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator/GeneratedRouteBuilderExtensions.g.cs:line 495
2023-05-23T10:56:13.4254264Z    at Microsoft.AspNetCore.Builder.GenerateRouteBuilderEndpoints.MapGet(IEndpointRouteBuilder endpoints, String pattern, Func`2 handler, String filePath, Int32 lineNumber) in /_/src/AdventOfCode.Site/Microsoft.AspNetCore.Http.RequestDelegateGenerator/Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator/GeneratedRouteBuilderExtensions.g.cs:line 47
2023-05-23T10:56:13.4256914Z    at Program.<Main>$(String[] args) in /_/src/AdventOfCode.Site/Program.cs:line 125
2023-05-23T10:56:13.4257501Z    at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
2023-05-23T10:56:13.4258095Z    at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
2023-05-23T10:56:13.4259446Z --- End of stack trace from previous location ---
2023-05-23T10:56:13.4260102Z    at Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.DeferredHost.StartAsync(CancellationToken cancellationToken)
2023-05-23T10:56:13.4260856Z    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Start(IHost host)
2023-05-23T10:56:13.4262418Z    at MartinCostello.AdventOfCode.Api.HttpServerFixture.CreateHost(IHostBuilder builder) in /_/tests/AdventOfCode.Tests/Api/HttpServerFixture.cs:line 99
2023-05-23T10:56:13.4263185Z    at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.ConfigureHostBuilder(IHostBuilder hostBuilder)
2023-05-23T10:56:13.4264532Z    at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
2023-05-23T10:56:13.4265181Z    at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
2023-05-23T10:56:13.4266580Z    at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers)
2023-05-23T10:56:13.4267706Z    at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
2023-05-23T10:56:13.4268366Z    at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient()
2023-05-23T10:56:13.4269716Z    at MartinCostello.AdventOfCode.Api.ApiTests.Api_Returns_400_If_Puzzle_Content_Incorrect() in /_/tests/AdventOfCode.Tests/Api/ApiTests.cs:line 309
2023-05-23T10:56:13.4271000Z --- End of stack trace from previous location ---

.NET Version

8.0.100-preview.4.23260.5

Anything else?

Curiously, this issue didn't happen for me locally, but only once I pushed it up to the repo and the GitHub Actions CI ran. Maybe it's got something to do with deterministic builds/CI in the source paths?

Metadata

Metadata

Assignees

No one assigned

    Labels

    NativeAOTNeeds: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Theme: cloud nativearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdg

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions