Yesterday, I ran into a strange problem, which I will try to describe below:
- We have a nice application, with a custom site definition that makes use of a custom site definition provider.
- That provider creates a publishing page, based on a custom page layout. This page layout includes the OOTB Content Editor WebPart. (the reason to create this page with the provider is valid, so no discussion about that ;))
- When we create a new site collection, based on this site definition, everything works fine.
Then, a new WSP is deployed.. This WSP includes some safecontrols and some assemblies that are deployed to the private bin of the web application..
- When we try to create the site collection again, an error occures: no parameterless contstructor defined.
- Tthe sitedefinition doesn't make use of any of the new functionality.
- Still, there is an error.
After some trial and error, and some smart thinking, we came op with the following possible solutions:
- When we remove the webpart from the page layout, everything works fine, again. But that is not the solution: it's no option for us.
- When removing the safe controls for the new WSP and we deploy the WSP, the creation of the site collection works.
- When adding the the assemblies to the GAC, everything works perfect.
- When adding the assemblies to the private bin of the Central admin, everything works perfect, too.
But I guess that you are more interested in the fact why the creation fails:
- When creating a site collection, this happens under the account of the logged in account of the Central Admin (when not using the self service).
- This Central Admin doesn't have any of the custom assemblies in it's private bin.
- The Central Admin doesn't have any of the custom safecontrols specified, although it does have a safecontrol for the Content Editor WebPart.
- When creating a site collection on web application X, that adds usercontrols/webparts to a page during creation (with a custom provisioning provider), SharePoint tries to load all controls that are present in the safecontrols section of the target web application. I don't know yet if the safecontrols are loaded from the webapplication's web.config or that it's loaded from the SharePoint content/configuration database, but that isn't much of an issue now.
- When creating a site collection on web application X, that doesn't add any custom user controls/webparts to a page during creation, the safecontrol section isn't loaded.
- It looks like that when a site collection is created from the central admin, and there is a user control that has to be added, the safecontrols section of the target webapplication is used, while the private bin directory of the Central Admin is used. This explains why the SC collection doesn't fail when the custom assembly is in the private bin.
- I have to note: I am not sure if safecontrols are loaded or not, but I expect them to be loaded. It's of course an possibility that on creation of a sitecollection, all these sections are ignored and all controls are added.
- But it doesn't have any influence on our problem.
Conclusion: When a site collection is created from the Central Admin to a webapplication that isn't the same as the Central Admin's web application, the private bin of the Central Admin is used. Because the custom wsp with its assemblies is only deployed to the target webapplication, those assemblies can't be loaded. Et voilá: an error occures.
But why can the Content Editor WebPart be loaded, then?
- The assembly containing the CEWP is in the GAC. This explains why the site collection creation doesn't fail when the assembly is in the GAC.
It looks like that , on creation, the safe controls of the t