‘Data is Null’ Search Error for Indexing Local SharePoint Sites

After months of search indexing working perfectly in SharePoint 2010 on the Local SharePoint Sites, we all of a sudden began to get errors on every single page in our content site collection.  This is the error that we found in the Search Service Application: Crawl Log.

The SharePoint item being crawled returned an error when requesting data from the web service. ( Error from SharePoint site: Data is Null. This method or property cannot be called on Null values. )

After some research it was suggested that it could be related to an SPGroup on the site collection that was create programmatically with a null description.  Here is example code of how SPGroups are created and where this issue would occur.

using(SPWeb web = SPContext.Current.Site.RootWeb)
{
//PARAMETERS: Group Name, Group Owner, Default User, Description
web.SiteGroups.Add(“New Group Name”,  SPContext.Current.Web.CurrentUser, SPContext.Current.Web.CurrentUser, null);

web.Update();
}

Obviously our issue did not stem from explicitly passing NULL as the description but our function that handled group creation took the description in as a parameter.  We fixed this function to make sure that it never attempts to create a group with a null description but we still needed to figure out which group or groups were causing the problem.  To handle this, I created a quick Powershell Script that cycles through all of the SPGroups in the root web and corrects any groups that have this issue.  Below is the code for that script:

#PARENT WEB
$parentWeb = “http://rootweburl/”

#GET THE PARENT WEB
$web = Get-SPWeb $parentWeb

if($web) {
foreach($group in $web.SiteGroups){
if($group.Description -eq $null) {
Write-Host $group.Name
$group.Description = $group.Name
$group.Update()
}
}
}

#DISPOSE OF PARENT WEB
$web.Dispose()

After running this script (where we found the 1 group that was the culprit) I was able to run a full index on the Local SharePoint Sites and everything was resolved.

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Advertisements
%d bloggers like this: