Quantcast
Channel: Optimizely Search & Navigation
Viewing all articles
Browse latest Browse all 6894

ContentDeliveryApi: System.InvalidOperationException: 'The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized()

$
0
0

Hello,

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.

Current configuration

web.config

I have an option to disable MapHttpAttributeRoutes:

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

MapHttpAttributeRoutes

I already had one invocation of the MapHttpAttributeRoutes in my application.

That is:

[ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
public class SiteInitialization : IConfigurableModule
{
   // ...
  public void ConfigureContainer(ServiceConfigurationContext context)
  {
    // ...
    GlobalConfiguration.Configure(config =>
    {
    // ...
    config.MapHttpAttributeRoutes();
    });
  }
}

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).

EnsureInitialized

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
  }
}

Episerver versions

The .NET Framework is 4.8.

  • EPiServer.Azure: 10.0.1
  • EPiServer.CMS: 11.15.0
  • EPiServer.CMS.AspNet: 11.15.0
  • EPiServer.CMS.Core: 11.15.0
  • EPiServer.CMS.TinyMce: 2.10.1
  • EPiServer.CMS.UI: 11.24.1
  • EPiServer.CMS.UI.AspNetIdentity: 11.24.1
  • EPiServer.CMS.UI.Core: 11.24.1
  • EPiServer.Commerce: 13.18.0
  • EPiServer.Commerce.Azure: 14.0.4
  • EPiServer.Commerce.Core: 13.18.0
  • EPiServer.Commerce.UI: 13.18.0
  • EPiServer.Commerce.UI.CustomerService: 13.18.0
  • EPiServer.Commerce.UI.ManagerIntegration: 13.18.0
  • EPiServer.ContentDeliveryApi.Cms: 2.10.0
  • EPiServer.ContentDeliveryApi.Core: 2.10.0
  • EPiServer.Framework: 11.15.0
  • EPiServer.Framework.AspNet: 11.15.0
  • EPiServer.Logging.Log4Net: 2.2.2
  • EPiServer.Personalization: 1.0.0
  • EPiServer.Personalization.Commerce 3.2.12
  • EPiServer.Personalization.Common: 3.1.0
  • EPiServer.Personalization.MaxMindGeolocation: 1.0.0
  • EPiServer.ServiceLocation.StructureMap: 2.0.3
  • EPiServer.Session: 1.0.0
  • EPiServer.Tracking.Commerce 3.2.12
  • EPiServer.Tracking.Core: 1.14.0

Thank you in advance!


Viewing all articles
Browse latest Browse all 6894

Trending Articles