The short story, when trying to execute SPListCollection.EnsureSiteAssetsLibrary
I get:
Exception calling "EnsureSiteAssetsLibrary" with "0" argument(s): "A list, survey, discussion board, or document library with the specified title already exists in this Web site. Please choose another title." At line:5 char:1 + $siteAssets = $currentWeb.Lists.EnsureSiteAssetsLibrary(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPException
And here's the longer version.
I have 2 environments (DEV and INT), both with the same 2007 migrated database. On each environment, I have this site collection with multiple subsites.
I developed a feature which is supposed to deploy some JS files in the Site Assets library on each subsite.
<Module Name="Scripts" Url="SiteAssets">
<File Path="Scripts\someScript.js" Url="someScript.js" Type="GhostableInLibrary"/>
....
</Module>
The problem is that originally, the 2007 subsites didn't have the Site Assets library, so the feature activation failed. In order to prevent that, I'm ensuring that the library exists through a PowerShell
script.
Now, when I execute the EnsureSiteAssetsLibrary
in PS, I get the error above only for some SPWebs
.
The behavior is inconsistent in DEV and INT, so that the number of SPWebs
on which the script fails is not the same (this could be or not be a hint for finding the right answer).
My question would be: why is the exception being thrown, when on MSDN we have the following remark?
If this list does not exist one is created and returned. If multiple such lists exist only one is returned.
[UPDATE]
It seems that the feature activation failure somehow corrupts the SPWeb (I also get these symptoms). In the ULS:
The list "$Resources:core,webpageassetList;" in web "..." was not created. hr = 0x81020012.
Failed to create list "$Resources:core,webpageassetList;" in web "...", HRESULT=0x1cf6a0d0. List XML: "<List xmlns:ows="Microsoft SharePoint" Title="$Resources:core,shareddocuments_Title_15;" Direction="$Resources:core,Direction;" Url="Shared Documents" BaseType="1"/>"