Fix: The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.

Scenario:
Trying to run a PowerShell script you get the following error:
The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.

Fix:
Run this PowerShell script:

Add-SPShellAdmin -username domain\user

Note:
Sometimes the fix is required although the Get-SPShellAdmin command returns the user as having shell admin privileges. It could be the case that not all the farm servers are in sync.

Fix: workflow does not start triggered by incoming email

Scenario:
Your SharePoint designer workflow is triggered by the creation of a new item through UI but not by the receiving of an email (which also creates a new item).

Script / Fix:

stsadm -o setproperty -pn declarativeworkflowautostartonemailenabled -pv true
Note:
You can also check the state of the declarativeworkflowautostartonemailenabled flag by running this command:
stsadm -o getproperty -pn declarativeworkflowautostartonemailenabled

Fix: cannot login to host-named site collection

Scenario:
You cannot login into a host-named site collection (SharePoint will prompt you for login over and over) while you can login to a non-host-names site collection on the same server.

Fix:

Update the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0\BackConnectionHostNames registry entry:
  1. Click Start, click Run, type regedit, and then click OK.
  2. In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
  3. Right-click MSV1_0, point to New, and then click Multi-String Value. Type BackConnectionHostNames, and then press ENTER.
  4. Right-click BackConnectionHostNames, and then click Modify.
  5. In the Value data box, type the host name or the host names for the sites that are on the local computer, and then click OK.
You may need to restart IIS.

Fix: The password supplied with the username ... was not correct. Verify that it was entered correctly and try again.

Scenario:
Trying to create a new web application fails with this message:
The password supplied with the username ... was not correct. Verify that it was entered correctly and try again.


Fix:
run this script:
stsadm -o updatefarmcredentials -userlogin <domain\username> -password <newpassword>

Note:
I just changed my windows account password and that may have triggered the issue.

Fix: No document templates uploaded for list "$Resources:core,MasterPageGallery;" -- none found for list template "100".

Scenario:
In SharePoint 2010, trying to create a Publishing Site with Workflow fails with this message:




The error logged is a bit more descriptive but not really helping:
No document templates uploaded for list "$Resources:core,MasterPageGallery;" -- none found for list template "100".

Fix:
Activate the "SharePoint Server Publishing Infrastructure" feature at the site collection level.
If the feature is active, deactivate it and then activate it again.


FIX: Coercion Failed: Unable to transform the input lookup data into the requested type.

Scenario:
When trying to set a lookup field value in a sharepoint designer workflow you get this error:
Coercion Failed: Unable to transform the input lookup data into the requested type.

Background:
In a sharepoint blog site I wanted to add the post category field to the comments list in a column called PostCategory (lookup on categories). I chose to use a workflow for this task. The workflow is triggered on item creation and update.

Here is the simple worklfow I have created:




The key is the "Return field as" field in the last dialogue box. I was getting the Coercion Failed error when setting the field type as integer. Setting it to lookup id (as integer) solved the problem.

FIX: Deployment was not performed for this project because it is a dependent project

Scenario:
Trying to deploy multiple SharePoint solutions from Visual Studio you are getting the following error:
Deployment was not performed for this project because it is a dependent project

You probably have a helper/utility project defined SharePoint project but with an empty package:




Fix:
Open the Configuration Manager (right click on the solution file in Solution Explorer and select Configuration Manager ...)
Clear the Deploy checkbox for your project.

FIX: Error MSB4018: The "ValidatePackage" task failed unexpectedly. The project service does not contain the specified project.

Scenario:
Your SharePoint solution build fails with this error:
The "ValidatePackage" task failed unexpectedly.
The project service does not contain the specified project.
and the GUID provided is the ID of the project you are trying to build

Build log:

...

  CopyFilesToOutputDirectory:
  Copying file from "obj\Debug\Helpers.dll" to "D:\Builds\Binaries\Helpers.dll".
  Helpers -> D:\Builds\Binaries\Helpers.dll
  Copying file from "obj\Debug\Helpers.pdb" to "D:\Builds\Binaries\Helpers.pdb".
(...): error MSB4018: The "ValidatePackage" task failed unexpectedly. [D:\Builds\SPTest\Helpers\Helpers.csproj]
(...): error MSB4018: System.InvalidOperationException: The project service does not contain the specified project: 618318f6-eff6-4fa9-9b39-3a9a6febb01b. [D:\Builds\SPTest\Helpers\Helpers.csproj]
(...): error MSB4018:    at Microsoft.VisualStudio.SharePoint.Tasks.ValidatePackage.OnCheckParameters() [D:\Builds\SPTest\Helpers\Helpers.csproj]
(...): error MSB4018:    at Microsoft.VisualStudio.SharePoint.Tasks.BuildTask.Execute() [D:\Builds\SPTest\Helpers\Helpers.csproj]
(...): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\Builds\SPTest\Helpers\Helpers.csproj]
(...): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() [D:\Builds\SPTest\Helpers\Helpers.csproj]
Done Building Project "D:\Builds\SPTest\Helpers\Helpers.csproj" (default targets) -- FAILED.

...

Fix C#:
Open the *.csproj in a text editor.
look for the <ProjectTypeGuids> entry and make sure the following guids are listed there:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...
    <ProjectTypeGuids>{BB1F664B-9266-4fd6-B973-E1E44974B511};{14822709-B5A1-4724-98CA-57A101D1B079};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    ...
  </PropertyGroup>
  ...
</Project>

Fix VB.NET:
Open the *.vbproj in a text editor.
look for the <ProjectTypeGuids> entry and make sure the following guids are listed there:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...
    <ProjectTypeGuids>{BB1F664B-9266-4fd6-B973-E1E44974B511};{D59BE175-2ED0-4C54-BE3D-CDAA9F3214C8};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
    ...
  </PropertyGroup>
  ...
</Project>
Note:
The above guids identify these project types:

{BB1F664B-9266-4fd6-B973-E1E44974B511} – SharePoint 2011 project
{C1CDDADD-2546-481F-9697-4EA41081F2FC} – SharePoint 2013 project
{14822709-B5A1-4724-98CA-57A101D1B079} – Workflow C# project
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} – C# project
{D59BE175-2ED0-4C54-BE3D-CDAA9F3214C8} - Workflow VB.NET project
{F184B08F-C81C-45F6-A57F-5ABD9991F28F} - VB.NET project

FIX: Error occurred in deployment step 'Recycle IIS Application Pool': Exception has been thrown by the target of an invocation.

Scenario:
Trying to deploy a SharePoint 2010 solution from Visual Studio 2012 you get this error:
Error occurred in deployment step 'Recycle IIS Application Pool': Exception has been thrown by the target of an invocation.

Output:

------ Deploy started: Project: Helpers, Configuration: Debug Any CPU ------
Deployment was not performed for this project because it is a dependent project.
------ Deploy started: Project: SiteColumns, Configuration: Debug Any CPU ------
Active Deployment Configuration: No Activation
Run Pre-Deployment Command:
  Skipping deployment step because a pre-deployment command is not specified.
Recycle IIS Application Pool:
Error occurred in deployment step 'Recycle IIS Application Pool': Exception has been thrown by the target of an invocation.
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Deploy: 1 succeeded, 1 failed, 0 skipped ==========

Background:
I am referencing some DLL files located in the "..\..\Binaries\Sharepoint" custom folder (this section in the *.csproj was generated by Visual Studio when I added references through the UI):
  <ItemGroup>
    <Reference Include="Microsoft.SharePoint.Linq, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
      <HintPath>..\..\Binaries\SharePoint\Microsoft.SharePoint.Linq.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
      <HintPath>..\..\Binaries\SharePoint\Microsoft.SharePoint.Publishing.dll</HintPath>
    </Reference>
    ...
  </ItemGroup>

Fix:
I removed the highlighted parts of the *.csproj above (version, culture, public key token and processor architecture), ending up with this:
  <ItemGroup>
    <Reference Include="Microsoft.SharePoint.Linq">
      <HintPath>..\..\Binaries\SharePoint\Microsoft.SharePoint.Linq.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.SharePoint.Publishing">
      <HintPath>..\..\Binaries\SharePoint\Microsoft.SharePoint.Publishing.dll</HintPath>
    </Reference>
    ...
  </ItemGroup>

FIX: 'XSLT compile error' on host-named site collection

Scenario:
On your host-named site collection you are trying to reference an XSLT file hosted in a SharePoint Library.
Assuming you have already checked that the xslt file is where it is expected to be.

Your code could look like this:

XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultCredentials;

XmlTextReader stylesheet = new XmlTextReader(xslLink);
stylesheet.XmlResolver = resolver;

XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(stylesheet);

On the last line you are getting this error:
XSLT compile error.
   at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
   at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
   at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
   at System.Xml.Xsl.XslCompiledTransform.CompileXsltToQil(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
   at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
   at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet)

Fix:
On the SharePoint server, add the host-name and IP in the "hosts" file (%systemroot%\system32\drivers\etc\hosts). Your new entry should look like:
10.10.10.190 SharePointTest.microsoft.com 
10.10.10.190 is the server's public IP address
SharePointTest.microsoft.com is your site collection host-name

Cause:
SharePoint is trying to access the XSLT file using a URL like:
http://SharePointTest.microsoft.com/Styles/MyStyleFile.XSLT
and it cannot reach the named address http://SharePointTest.microsoft.com

Note: The change will not take effect immediately. You can wait a few minutes or try this command:
ipconfig /flushdns

FIX: Duplicate field in list view form

Scenario:
One or more list fields appear twice on the forms associated to a list (new, edit and view). There are no duplication in the list columns. The list is using a custom content type.

For example the Answer field shows twice on the New FAQ form:


Things to look for:
Check that the field/column is not declared twice in the list settings page.

Cause:
I have seen this happening in 2 cases:
1. when changing and re-deploying the underlying content type
2. when migrating lists from one site to the other (using PowerShell in my case)

Fix:
Browse to the list settings page (on the List Tools - List ribbon click on the List Settings icon)

In the Content Types section click on the content type link

Remove the duplicated column

FIX: PowerShell Remoting fails

Scenario:
Your attempt to remote using PowerShell fails with this message:
Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you have the appropriate permissions to access the database before trying again.

Fix:
1. On the remote machine run the following PowerShell script:

#Enable Windows PowerShell Remoting 
Enable-PSRemoting -Force 
#Enable CredSSP support 
Enable-WSManCredSSP -Role Server -Force 
#Increase memory limit for remote shell 
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000

2. On the client machine run the following PowerShell script:
#enable CredSSP on the client:  
Enable-WSManCredSSP -Role Client -DelegateComputer * -Force   
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Credssp\PolicyDefaults\AllowFreshCredentials -Name WSMan -Value WSMAN/*   
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Credssp\PolicyDefaults\AllowFreshCredentialsDomain -Name WSMan -Value WSMAN/*

Props:
Josh Gavant: PowerShell Remoting for SharePoint

FIX: The operation could not be completed because item was removed from the gallery

Scenario:
You attempt to add a custom web part to a webpage fails with this message:
The operation could not be completed because item was removed from the gallery

Fix:
1. Remove the web part from the web part gallery:
http://site:port/_catalogs/wp/Forms/AllItems.aspx

2. Disable and the re-enable the feature containing the web part (at the web or the site collection level) to add the web part back to the gallery.


FIX: The site is not valid. The 'Pages' document library is missing

Scenario:
Trying to create a new page fails with this error:

Microsoft.SharePoint.Publishing.InvalidPublishingWebException: The site is not valid. The 'Pages' document library is missing.    
at Microsoft.SharePoint.Publishing.PublishingWeb.GetPublishingListWithCleanup(PublishingListType list, Boolean throwExceptionOnInvalidWeb)     
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.BasePageSettingsPage.get_PageListRoot()     
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.BasePageSettingsPage.SetParentUrlLabel()   
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.BasePageSettingsPage.LoadValues()     
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.CreatePagePage.LoadValues()     
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.BasePageSettingsPage.OnLoad(EventArgs e)     
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.CreatePagePage.OnLoad(EventArgs e)     
at System.Web.UI.Control.LoadRecursive()     
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Fix: runt this PowerShell script:
$web = get-spweb http://site:port/web
$newId = $web.Lists["Pages"].ID
$web.AllProperties["__PagesListId"] = $newId.ToString()
$web.Update()

FIX: Custom timer job triggered multiple times

Scenario:
In a SharePoint farm, your custom timer job fires on each server of your farm. You only want it to fire once.

Fix:
You will find countless sites offering solutions for this problems and most of them do not work.

You are probably implementing a class inheriting from SPJobDefinition:

   class TimerJob : SPJobDefinition  { ... }  

SPJobDefinition has two public constructors (and one reserved for internal use):
     // Parameters:  
     //  name: Specifies the name of the job definition.  
     //  service: Specifies an Microsoft.SharePoint.Administration.SPService object instance.  
     //  server: Specifies an Microsoft.SharePoint.Administration.SPServer object instance.  
     //  lockType: Specifies an enumeration value from the Miccrosoft.SharePoint.Administration.SPJobLockType enum.  
     protected SPJobDefinition(string name, SPService service, SPServer server, SPJobLockType lockType);  

     // Parameters:  
     //  name: Specifies the name of the job definition.  
     //  webApplication: Specifies an Microsoft.SharePoint.Administration.SPWebApplication  
     //  server: Specifies an Microsoft.SharePoint.Administration.SPServer object instance.  
     //  lockType: Specifies an enumeration value from the  
 object instance.  
     protected SPJobDefinition(string name, SPWebApplication webApplication, SPServer server, SPJobLockType lockType);  
 pe);  

It would seem that setting lockType to SPJobLockType.Job solves the problem. The job should only run once per job instance. In fact, unless you also specify an application server, the job will still run on ever server in the farm, therefore multiple times.

Suggested implementation:

Timer class:
 class TimerJob : SPJobDefinition {  
     public TimerJob(SPWebApplication webApp, SPServer server)  
       : base(JobTitle, webApp, server, SPJobLockType.Job)  
     {  
       Title = JobTitle;  
     }  
 ...  
 }  

Create the timer (in a SPFeatureReceiver for example):
   public class OrbisTaskMessengerEventReceiver : SPFeatureReceiver  
   {  
     public override void FeatureActivated(SPFeatureReceiverProperties properties)  
     {  
       CreateJob(properties.Feature.Parent as SPSite);  
     }  
     //create the timer job  
     private static void CreateJob(SPSite site) {  
       SPServer server = RandomApplicationServer(site);  
       if (server != null) {  
         TimerJob job = new TimerJob(site.WebApplication, server);  
         SPDailySchedule schedule = new SPDailySchedule { BeginHour = 7, EndHour = 8 };  
         job.Schedule = schedule;  
         job.Update();  
       }  
       else {  
         throw new System.Exception("Failed to create job; cannot determine an Application server in the farm.");  
       }  
     }  
     //find a random application server in the farm  
     private static SPServer RandomApplicationServer(SPSite site) {  
       foreach (SPServer server in site.WebApplication.Farm.Servers) {  
         if (server.Role == SPServerRole.Application)  
           return server;  
       }  
       return null;  
     }  

FIX: The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered

Scenario:
You try to run a PowerShell script and the script fails with this message:
The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered

Cause:
When you run this cmdlet to add a user to the SharePoint_Shell_Access role, you must have membership in the securityadmin fixed server role on the SQL Server instance, membership in the db_owner fixed database role on all affected databases, and local administrative permission on the local computer.

Fix:
Run this script in PowerShell:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue; 
Add-SPShellAdmin -UserName Domain\UserName;

More on Add-SPShellAdmin:
http://technet.microsoft.com/en-us/library/ff607596.aspx