SharePoint hotfix 939077 partially breaks Advanced Search

Microsoft released a hotfix package for SharePoint Server 2007 and for SharePoint Server 2007 for Search. This hotfix package fixes an issue where sites that use forms-based or cookie-based authentication are not being crawled in SharePoint. It also fixes an issue where slow performance of the BLOB cache is experienced. The latter is the reason why we installed this hotfix on the production environment of a client I’m currently working at.

The hotfix addresses the issues just fine. However, on our environment it appears to be introducing a new issue: It breaks the out of the box SharePoint Advanced Search Box web part with the following dreaded error: “Object reference not set to an instance of an object.” 

This is all the information you’re getting, no stack trace, nothing in the logs. This pretty much left me clueless. At first I thought I screwed something up with my own search settings. That feeling got stronger after I created a default Search Center site: the Advanced Search web part was still working there.

After some puzzling I concluded that it had to be a difference in the web part properties, since it appeared to be working on the default Search Center site. So I exported both web parts, and examined the differences…and indeed, the only differences where property settings.

Right, back to my non-working version of the web part. In my version I was hiding the Properties section which is visible in the default web part. After making it visible on my web part again, it worked! So much for testing your hotfixes before rolling them out…

The problem is definitely the hotfix. I also installed it on my development environment and it broke the Advanced Search web part as well…

The hotfix cannot be uninstalled, so now we’re pretty much waiting for the hotfix-hotfix from Microsoft. For now, I guess I’ll just have to remove the Advanced Search web part from the search results page.

SPWeb.AvailableContentTypes or SPWeb.ContentTypes?

There are two ways to get a collection of content types for a web site. One is the SPWeb.AvailableContentTypes collection and the other one is the SPWeb.ContentTypes collection. Right, what’s the difference then, I hear you say. A quote from the MSDN documentation:

Gets the collection of all content type templates for the current scope, including those of the current Web site, as well as of any parent sites.

Use the ContentTypes property to return only the content types of the current Web site.

The documentation is not very extensive here. The difference really is a bit vague. For you programmers out there it is good to realize that an important difference between the two exists. The AvailableContentTypes collection is read-only!

Allow me to ellaborate a bit more on that. A while ago I tried to programmatically add an information management policy to a content type (I’ll write something on that later). So, I retrieved the content type like this:

SPWeb web = SPContext.Current.Web;
SPContentType contentType = web.AvailableContentTypes[new SPContentTypeId(myContentTypeId)];

When trying to add the policy to the content type, I just kept getting an error: “The collection cannot be modified”. This seemed very strange to me, and I couldn’t figure it out at first. Google and MSDN both were not very helpful in trying to find out what went wrong.

The stack trace informed me that the error occurred when the SPContentType.Update() method was called. So I started up Reflector (this really is a must-have tool for working with MOSS 2007, sad but true) to see what was happening in that method. After a while I found out that when you access the AvailableContentTypes property, a read-only collection of SPContentType objects is returned. Everything worked fine when I used the SPWeb.ContentTypes collection.

Right, that pretty much made me feel like banging my head against the wall. I spent a couple of hours trying to figure out why it wouldn’t work and it turns out to be so easy. Those are the moments when you wish that the MSDN documentation would contain more information than just a basic description of a property.

Of course, thinking about it, it probably makes sense that the AvailableContentTypes property is read-only. After all, it does return content types that belong to the parent site and you probably won’t want to go around editing those directly from a child site. Oh well, let us just be grateful that Reflector exists.

For all of those who have been living in a cave lately, here is a link to the site where Reflector can be downloaded:

http://www.red-gate.com/products/reflector/

Hello world!

Hm, being a programmer myself, I probably should leave the title like this. Well, first of all: welcome to my blog. I figured I should write a little bit more about the work I do currently. Events that have occurred in the last couple of weeks reminded myself that I should document what I’m doing.

 So, the goals of this blog are:

- Writing about Microsoft Office SharePoint Server 2007 (in short: MOSS 2007);
- Share my knowledge with anyone who is interested;
- Keep an archive for myself of anything that I encounter during work;