Wednesday 6 July 2011

Powershell command to access Microsoft.SharePoint assembly does not work

I wanted to list the set of resource measures on the SharePoint environment that I am working on. To get the list of resource measures we can use powershell, using the command
[Microsoft.SharePoint.Administration.SPUserCodeService]::Local.ResourceMeasures
I encountered the following error in the console.
Unable to find type [Microsoft.SharePoint.Administration.SPUserCodeService]: make sure that the assembly containing this type is loaded.
At line:1 char:56
+ [Microsoft.SharePoint.Administration.SPUserCodeService] <<<< ::Local.ResourceMeasures + CategoryInfo : InvalidOperation: (Microsoft.Share...UserCodeService:String) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound


Solved:
The problem was because SharePoint powershell snap in was not loaded.
The command to load the SharePoint powershell snap in is as follows. We need to just run this command in the powershell command prompt.
Add-PSSnapin Microsoft.SharePoint.Powershell

Error : Sandboxed Solution deploy

I created a sandbox solution. While working on the solution I added a Sharepoint mapped image folder to the solution. In visual studio when I clicked deploy of the project I encountered the following error.
The deployment type "TemplateFile" of file "ALLMTGS.GIF" in Project Item "Images" is not compatible with a Package in a Sandboxed Solution.
The Project Item "Images" cannot be deployed through a Package in a Sandboxed Solution.


Solved:
The cause of the problem was that, I created a Sandboxed solution. A Sandboxed solution does not support disk operations. I changed the solution type from Sandboxed to farm solution and the deployment worked fine. Below are the steps I followed in visual studio to change the sandboxed solution to a farm solution.
  1. In the solution explorer, select the sharepoint project that is to be deployed
  2. With the selection on the project, navigate to the properties window (press F4)
  3. Change the value of the property 'Sandboxed Solution' to 'false'
  4. An alert will be displayed asking if you have farm administrator previleges. Click 'OK'

Tuesday 5 July 2011

Error when upgrading sandbox solution

The URL '_catalogs/solutions/mysolutions.wsp' is invalid. It may refer to a nonexistent file or folder, or refer to a valid file of folder that is not in the current Web.

I encountered this error when trying to upgrade a sandbox solution in Sharepoint 2010.

Solved:
The problem was due to a feature template xml having a wrong namespace given to the assembly name for the feature receiver attributes. I corrected the namespace problem and the upgrade started working fine.
The corrected section of the feature.template.xml goes like this.
<UpgradeActions ReceiverAssembly="HelloWorld, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b2135059549c7590"
ReceiverClass="HelloWorld.Features.HelloWorldFeature.HelloWorldFeatureEventReceiver">