[{"data":1,"prerenderedAt":98},["ShallowReactive",2],{"/2026/01/28-swagger-.net-8-error":3},{"id":4,"title":5,"body":6,"date":89,"description":44,"extension":90,"meta":91,"navigation":92,"path":93,"robots":94,"seo":95,"stem":96,"__hash__":97},"posts/2026/01/28 swagger-.NET-8-error.md","28 Swagger NET 8 Error",{"type":7,"value":8,"toc":86},"minimark",[9,18,25,28,31,45,47,50,52,55,57,60,68,70,73,75,78],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"swagger-net-8-error","Swagger .NET 8 Error",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 9/13/2024.",[26,27],"br",{},[22,29,30],{},"Swashbuckle CLI was able to output schema of my API before, but this time, it throws this error message:",[32,33,34],"code-block",{},[35,36,41],"pre",{"className":37,"code":39,"language":40},[38],"language-text","System.InvalidOperationException: A type named 'StartupProduction' or 'Startup' could not be found in assembly\n","text",[42,43,39],"code",{"__ignoreMap":44},"",[26,46],{},[22,48,49],{},"I used top level statement with minimal API on .NET 8 and nothing is changed on that, so I was not able to find anything to do with Startup type.",[26,51],{},[22,53,54],{},"After I investigate further by commenting line by line, I found out that the issue is on my switch statement.",[26,56],{},[22,58,59],{},"So it looks like the following:",[32,61,62],{},[35,63,66],{"className":64,"code":65,"language":40},[38],"return config.Section?.Key switch\n{\n  Value1 => services.AddSingleton\u003CHandler1>(),\n  Value2 => services.AddSingleton\u003CHandler2>(),\n  _ => throw new InvalidOperationException();\n}\n",[42,67,65],{"__ignoreMap":44},[26,69],{},[22,71,72],{},"Problem is the Section is pulled from appsettings.json and when the CLI runs, it doesn't have value, so it never returned the services object.",[26,74],{},[22,76,77],{},"Changing the above to the following fixed the issue:",[32,79,80],{},[35,81,84],{"className":82,"code":83,"language":40},[38],"return config.Section == null ? services : config.Section.Key switch\n{\n  Value1 => services.AddSingleton\u003CHandler1>(),\n  Value2 => services.AddSingleton\u003CHandler2>(),\n  _ => throw new InvalidOperationException();\n}\n",[42,85,83],{"__ignoreMap":44},{"title":44,"searchDepth":87,"depth":87,"links":88},2,[],"2026-01-28T00:00:00.000Z","md",{},true,"/2026/01/28-swagger-.net-8-error",null,{"title":5,"description":44},"2026/01/28 swagger-.NET-8-error","A45L66nwUv5Pwz8m0k5GvJ38Si6D3_8nch-80_xpgK4",1785167451682]