views:

27

answers:

1

Hi all, I'm working on a automated script for deploying sharepoint projects. I'm using a sandbox level webtemplate that must be applied when de site is created. I had a lot of troubles doing that because it seems like sharepoint caches the list of webtemplates and get-spwebtemplate doens't find the new added one. The way I made it work is this:

[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$site= new-Object Microsoft.SharePoint.SPSite($web_application_complete_url)
$site.OpenWeb().ApplyWebTemplate($web_template_name)
$site.Dispose()

As you can see, I'm using the .net sharepoint api instead of the cmdlets. This works sweet in PowerShell ISE but in the PowerShell console it throws an exception regarding a referenced DLL:

Exception calling "ApplyWebTemplate" with "1" argument(s): "Could not load file or assembly 'XXX.SharePoint.Common, Version=1.0.0.0, Culture=neutral, PublicK eyToken=534c125b45123456' or one of its dependencies. The system cannot find th e file specified." At C:\Build\SharePointBuild.p s1:318 char:37 + $site.OpenWeb().ApplyWebTemplate <<<< ($web_template_name) + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE xception + FullyQualifiedErrorId : DotNetMethodException

The assembly is perfectly registered in the GAC when installing the web template sandbox solution in the sitecollection.

Any ideas? thanks!

A: 

Is there any chance you are running 64-bit ISE and 32-bit PowerShell console (or vice-versa)? If it's not that then another difference is that ISE runs in COM STA mode whereas PowerShell Console runs in MTA by default. This would only matter if SharePoint uses COM under the covers (which I think it does). You could verify this by running PowerShell Console in STA mode like so:

C:\> Start-Process PowerShell -arg -sta

Assuming you're on PowerShell 2.0 for the Start-Process cmdlet.

Keith Hill
Thanks for your reply! Since I have both 64 and x86 powershell executables, I think both are working on 64bits. I tried the -sta parameter when opening powershell and it dosn't work. However, I will try your way
ivos
...and it didn't work :(
ivos
In this case, you may try using the tool fuslogvw.exe from the Windows SDK. It will display more information about assembly loading failures. Here's a help topic on how to use this tool: http://msdn.microsoft.com/en-us/library/e74a18c4%28VS.71%29.aspx
Keith Hill