Aftert installing EPiServer.CloudPlatform.Cms and the dependent package EPiServer.Cms.HealtCheck all my ApiControllers (web api) stopped working and I got his error. An important pice of information is that the web api's that got the error (se below) were set up this attribute routing!
ERROR: "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 have a webapiconfig.cs with a register method, where I call this:
public class MyApiController : ApiController
{
[HttpGet]
[Route("test")]
public int test()
{
return 42;
}
}
So attribute routing is set up using GlobalConfiguration.Configure.MapHttpAttributeRoutes(), and after some reflection of the EPiServer.Cms.HealthCheck packages I figured out that this module also were calling GlobalConfiguration.Configure.MapHttpAttributeRoutes(), but that it was possible to disalbe.
SOLUTION: A appSetting key kan be used to disable the extra call to MapHttpAttributeRoutes for the HealthCheck module
This is a lifesaver! Does anyone know why installing the EPiServer.CloudPlatform.Cms package causes this? Our API endpoints ceased to work for a few months due to this and we only realized a week ago. I found several topics with the specific error message but none of the suggestions / solutions worked, until I encountered this one.
Info: The service api has a similar appsettingskey for disabling the same thing: https://world.optimizely.com/documentation/developer-guides/archive/service-api/installation-and-configuration/3-4/
Aftert installing EPiServer.CloudPlatform.Cms and the dependent package EPiServer.Cms.HealtCheck all my ApiControllers (web api) stopped working and I got his error. An important pice of information is that the web api's that got the error (se below) were set up this attribute routing!
ERROR: "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 have a webapiconfig.cs with a register method, where I call this:
And in Global.asax.cs I have this:
and also this in the end of Application_Start() in global.asax.cs:
My controller looks like this:
So attribute routing is set up using GlobalConfiguration.Configure.MapHttpAttributeRoutes(), and after some reflection of the EPiServer.Cms.HealthCheck packages I figured out that this module also were calling GlobalConfiguration.Configure.MapHttpAttributeRoutes(), but that it was possible to disalbe.
SOLUTION: A appSetting key kan be used to disable the extra call to MapHttpAttributeRoutes for the HealthCheck module
This is setting is not documented any place by Optimizely, that I can find...