ClassFactory not initialized

  • Posted: Mar 24 2009
  • Versions: EPiServer CMS 5
  • FAQ number: 229

Question

When upgrading a Web site to EPiServer CMS 5 R2 we are getting the server error stating - ClassFactory not initialized.


Answer

This behaviour could be due to that in your application you are using EPiServer CMS CacheManager or other internal objects that are related to EPiServer.DataFactory before the real begin_Request arrives into the system. 

If a module uses the CachManager or DataFactory before receiving the FirstBeginRequest it can lead to strange behavior or even an exception when there is an attempt to access DataFactory. 

You can ONLY use the events of the DataFactory object in the HttpModule.Init(). This means that in the init method of a custom module you can ONLY subscribe to the Dafactory Events. 

A code example is provided below showing one way how to handle initialization of a custom module in EPiServer.

// It is a way to init things which related to
// EPiServer Module.Init().
public void Init(HttpApplication context)
{
     Global.Application_FirstBeginRequest +=
      new EventHandler(Global_Application_FirstBeginRequest);

      // a void call to CacheManager wait
      // to get event from Global object
      // you can subscribe on datafactory event  
}

 

// When you receive the FirstBeginRequest event then
// it is safe to access the EPi Internal objects.
void Global_Application_FirstBeginRequest
     (object sender, EventArgs e)
{
   // Here should be code for Initilization
   // object which is related to EPiServer
   // CacheManager etc
}

Please Note for EPiServer CMS R2 SP1 and after

From EPiServer CMS 5 R2 SP1 the initialization module is moved from the EPiServer.Global to EPiServer.Web.Initialization - the handler should be as below from EPiServer CMS 5 R2 SP1 :

EPiServer.Web.InitializationModule.FirstBeginRequest += new EventHandler(Global_Application_FirstBeginRequest);

 

FeedBackbutton image