Error get web api to work

Vote:
 

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:

GlobalConfiguration.Configuration.MapHttpAttributeRoutes();

And in Global.asax.cs I have this:

GlobalConfiguration.Configure(WebApiConfig.Register);

and also this in the end of Application_Start() in global.asax.cs:

GlobalConfiguration.Configuration.EnsureInitialized();

My controller looks like 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

  <add key="episerver:healthcheck:maphttpattributeroutes" value="false" />

This is setting is not documented any place by Optimizely, that I can find...

#299991
Edited, Apr 12, 2023 19:39
WilliamP - Oct 02, 2024 12:53
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.
Vote:
 

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/

#299992
Apr 12, 2023 19:41
Vote:
 

The answer is inside the forum post;)

#299993
Apr 12, 2023 19:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.