views:

487

answers:

3

I've recently started work on a new project using EpiServer which I am totally new to. One of my tasks requires me to write a custom page provider.

I have got the sample page provider working and loaded. I've also ensured that I have a Enterprise Developer licence as the functionality is only available with this licence.

So I've done a skeleton implementation of my page provider and entered the info into the web.config on my test site exactly as the XmlPageProvider sample does thusly:

    <pageProvider>
      <providers>
        <add entryPoint="26" capabilities="Create,Edit,Delete,Move,MultiLanguage" 
          name="custom" type="MyWebsite.CustomProvider,CustomPageProvider" />
  <!--  <add filePath="~/externalPages.xml" entryPoint="26" capabilities="Create,Edit"
          name="xml" type="CodeSamples.XmlPageProvider,XmlPageProvider" />-->
      </providers>
    </pageProvider>

While we're at it what is the entryPoint property referring to? I cannot find a satisfactory explanation for this anywhere. When I hit the page however I see the following.

Error occured 2/2/2009 10:07:26 AM User IP fe80::d0e0:16bf:c536:ad4d%10 User Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618) Url http://ioc-dev-uk5:17003/cms/admin/default.aspx Referer (none)

Exception details: TypeInitializationException: The type initializer for 'EPiServer.DataFactory' threw an exception.

Stack trace:

[TypeInitializationException: The type initializer for 'EPiServer.DataFactory' threw an exception.] at EPiServer.Web.InitializationModule.Initialize(EPiServerSection config, Settings settings, ConnectionStringSettingsCollection connectionStringSettings) at EPiServer.Web.InitializationModule.StaticInitialization() at EPiServer.Web.InitializationModule.Application_BeginRequest(Object sender, EventArgs e) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

[Inner exception ArgumentException: Cannot create an instance of type MyWebsite.CustomProvider,CustomPageProvider] at EPiServer.Core.PageProviderMap.AddPageProvider(ProviderSettings pageProviderSetting) at EPiServer.Core.PageProviderMap.LoadPageProviders(ProviderSettingsCollection pageProvidersCollection) at EPiServer.Core.PageProviderMap..ctor(ProviderSettingsCollection pageProviders) at EPiServer.DataFactory..cctor()

As you can see this is fairly unhelpful. I've tried getting another licence, resetting IIS, rebooting the box, trying to work out what's going on using reflector to look at the code in the EpiServer DataFactory, all to no avail.

I know it's something really simple but what?! It's been driving me mildly insane for about 2 days now.

Plaese Halp!

+1  A: 

Guess I'm answering this myself.

It was really simple.

Went in with reflector and found this:

private void AddPageProvider(ProviderSettings pageProviderSetting)
{
    if (Type.GetType(pageProviderSetting.Type) == null)
    {
        throw new ArgumentException("Cannot create an instance of type " + pageProviderSetting.Type);
    }
    PageProviderBase pageProvider = this.CreatePageProviderInstance(pageProviderSetting);
    pageProvider.Initialize(pageProviderSetting.Name, pageProviderSetting.Parameters);
    if (this._pageProviders.ContainsKey(UrlSegment.ReplaceIllegalChars(pageProvider.Name)))
    {
        throw new ArgumentException(string.Format("There is already a page provider with name {0} registered", pageProvider.Name));
    }
    this.AddPageProvider(pageProvider, false);
}

The type name required the full namespace on it, so my web.config now looks like:

<pageProvider>
  <providers>
    <add entryPoint="26" capabilities="Create,Edit,Delete,Move,MultiLanguage" 
      name="custom" type="MyWebsite.CustomProvider,MyWebsite.CustomProvider.CustomPageProvider" />
  </providers>
</pageProvider>

And we're all up and working...

Another example of bad error messaging. It should say "Could not locate type" would have saved a lot of messing about.

Rob Stevenson-Leggett
A: 

Thanks, it's help me too.

LockeVN
A: 

Hey, Thanks for such a valuable post.Please tell what should be the correct syntex if anyone is using XML Page Providers.

Bharti