Do you have any GlobalConfiguration.Configure in your code ?
@Quan Mai: Yes, single one -- the same as posted above.
That is probably the problem as ServiceAPI already called it. What do you do in there? Can it be done without using GlobalConfiguration.Configure?
@Quan Mai: Thank you for the answer.
When I remove GlogalConfiguration.Configure, the site loads correctly and I'm able to see APIs in Swagger UI.
Now, the question is -- how can I use GlobalConfiguration.Configure now?
Your application seems to already find the http map.
Since you already have web config entry where you are setting it false. Try removing config.MapHttpAttributeRoutes() and just keep config.Default()
while keeping the globalconfiguration.
Your suggestions helped me solving the problem, Quan Mai, Dileep D, thank you.
I have added ContentDeliveryApi (Cms and Core) to my application, but after that I'm receiving an error:
System.InvalidOperationException: 'The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.'
I followed similar topic (https://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2017/4/the-object-has-not-yet-been-initialized--ensure-that-httpconfiguration-ensureinitialized/), but none of these solutions did work.
I have an option to disable MapHttpAttributeRoutes:
<add key="episerver:serviceapi:maphttpattributeroutes" value="false" />
I already had one invocation of the MapHttpAttributeRoutes in my application.
public class SiteInitialization : IConfigurableModule
public void ConfigureContainer(ServiceConfigurationContext context)
But, after installation of ContentDeliveryApi packages, I'm receiving this error:
A route named 'MS_attributerouteWebApi' is already in the route collection. Route names must be unique.Parameter name: name
So, it seems there's one more invocation of the MapHttpAttributeRoutes in either EPiServer.ContentDeliveryApi.Cms or EPiServer.ContentDeliveryApi.Core.
When I removed the MapHttpAttributeRoutes from my SiteInitialization, I get the original System.InvalidOperationException (the subject of the thread).
I tried to add EnsureInitialized to my Global.asax.cs, but this didn't resolve the problem.
public class Global : EPiServer.Global
protected void Application_Start()
WebApiConfig.Register(GlobalConfiguration.Configuration); // this was already here
GlobalConfiguration.Configuration.EnsureInitialized(); // newly added, but it didn't help
The .NET Framework is 4.8.
Thank you in advance!