Monday, June 30, 2008

First speeding ticket

I got my first speeding ticket on the motorcycle the other day. In Holland you don't get pulled over, they just send you the ticket by mail a few weeks after they catch you. What is interesting is that I would never expect to be ticketed for doing 108 on a highway that has a 100 limit. That's right folks, I got a ticket for doing 8km/h over the speed limit. The ticket amounts to 16 Euro which is not that bad. Good lesson though, even a little bit of speeding will result in a not so nice piece of mail.

Thursday, June 26, 2008

Content Query Web Part Crashes

I had an interesting error thrown by the Content Query Web Part in MOSS 2007 today. I added the web part to the page, all seemed fine until I clicked 'Modify Shared Web Part'. At this point I get an ugly ASP.NET exception (I have custom errors turned off on my dev box) that says:

Key cannot be null.
Parameter name: key

After a few hours of hunting and digging, this was what I found:

Using Reflector I dug into what the web part was trying to do and realized it was iterating through the SPFields of the current web and using the Title property of each to index into an array. Since the exception was complaining that the key is null, I assumed one of the Title fields was null.

I then used powershell to see what my fields looked like and voila, one had a null title.

The last step was to go to the feature where our team is putting the site columns we are using and finding the guilty field. I noticed that the field had no DisplayName property and so I added this.

After a new deployent all was well again.

The powershell script I used:

# Script to find fields with a null Title

Function Find([string]$sitename){

  $site = [Microsoft.SharePoint.SPSite]($sitename)
  $web = $site.RootWeb
  $fields = $web.AvailableFields

  Write-Host " "
  Write-Host "Finding fields"

  for($i=0; $i -le ($fields.Count-1); $i++){
   if($fields[$i].Title -eq $null){
    Write-Host ""
    Write-Host "Found error in field:"
    Write-Host
    Write-Host "FieldName : ", $fields[$i].InternalName
    Write-Host "Collection index : ", $i.ToString()
   }
  }
}


[System.Reflection.Assembly]::Load(”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
[System.Reflection.Assembly]::Load(”Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
set-executionpolicy RemoteSigned

Find($args[0])



The stack trace (for googlers):


[ArgumentNullException: Key cannot be null.
Parameter name: key]
System.Collections.SortedList.IndexOfKey(Object key) +2422464
System.Collections.SortedList.get_Item(Object key) +12
Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.getFieldKey(SPField field) +59
Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.populateData() +1720
Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.populateCBQControls() +24
Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.CreateChildControls() +62
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +50
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041