HTTP Error 500.30 - ANCM In-Process Start Failure when using Swagger in ASP.NET Core Web API project
Problem
I have an ASP.NET CORE Web API (3.1) project with Swashbuckle.AspNetCore (6.1.1). When I run the project, I got this error below.

Error Message
Here is the error message that I got in Visual Studio Debug output windows.
(Inner Exception #1) System.InvalidOperationException: Error while validating the service descriptor ‘ServiceType: Microsoft.Extensions.ApiDescriptions.IDocumentProvider Lifetime: Singleton ImplementationType: Microsoft.Extensions.ApiDescriptions.DocumentProvider’: Unable to resolve service for type ‘Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider’ while attempting to activate ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’. —> System.InvalidOperationException: Unable to resolve service for type ‘Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider’ while attempting to activate ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’. at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type serviceType, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.<>c__DisplayClass7_0.b__0(Type type) at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type serviceType, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor) — End of inner exception stack trace — at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor) at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, ServiceProviderOptions options)<—
Solution
The solution is that you make sure that you have services.AddControllers(); in ConfigureServices(IServiceCollection services) method. If you don’t have it, please add that line. Your problem will be solved and you should be able to see the swagger page.
Example:
| |
One more tip ~
If you are getting this error below, you need to make sure that you have at least one controller that has a method with [Http{Verb}] e.g. [HttpGet].
Failed to load API definition.
Fetch errorundefined https://localhost:**/swagger/v1/swagger.json

Because you might be using the attribute-routed instead of conventional-routed. Please check this code endpoints.MapControllers() in Startup.cs.
| |
If you are using the attribute-routed, you need to have the followings in order to see the swagger image.
- At least one ApiController
- That ApiController should have
[Route("[controller]")]attribute. - It should have at least one method that has
[Http{Verb}]e.g.[HttpGet].
Please refer to the example code below.
| |
Hope it helps.
