Click here to Skip to main content
13,144,309 members (32,531 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am trying to create a site definition using webtemp*.xml and onet.xml. I am creating all my list instances through onet.xml only. I have a feature which I am using to manipulate a list in this site. I have this feature activated through the <sitefeatures> element in onet.xml. But when I try to create a site using this definition, everything works fine except the feature activation code. The activation code throws me an error - "Value does not fall within the expected range". On further investigating, I found that this is because the list instances are created only after the Site-scoped features and Web-scoped Features are activated and hence in my feature code when I am trying to fetch a particular list, I encounter this error. Could anyone help me out on this. I want the feature to be activated and code to be executed once the site is created through this definition.
Posted 1-Jun-12 18:28pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi all,
I just got the solution for this.
I did a research on this and found that the reason for the error being thrown is the order in which elements are provisioned through the definition in onet. SharePoint provisions in the following order:
1)global onet.xml
2)SPSite scoped features defined in onet.xml, in the order they are defined in the file.
3)SPSite scoped stapled features, in quasi random order
4)SPWeb scoped features defined in onet.xml, in the order they are defined in the file.
5)SPWeb scoped stapled features, in quasi random order
6)List instances defined in onet.xml
7)Modules defined in onet.xml

Reference :[^]

And since lists are created only after the Site and Web scoped features are provisioned, my feature code does not get the list it is searching for and hence throws the exception.
A work around to this solution that I have found out is -
First create a feature which will provision all your lists and through list instances.
Then activate the feature that is looking for the list (the feature which is throwing the error.)
I have tried this and it is working fine.

Another suggested work around that was found is creating the site definition using the SPWebProvisioningProvider class.
Please refer the link below -[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 6 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100