I am preparing some demos for a presentation regarding the search extensibility within SPS and WSS. Besides the stuff I have covered in my MSDN article on extending SPS search, I am also planning to do some things with WSS search. Now, Corasworks has a nice free Web part that you can download allowing you to search on keywords within your team site and the sub sites under it. Using the smart part, I started to recreate this, basically utilizing the SearchListItems and SearchDocuments methods of the SPWeb object.
When executing my first snippet of code like the one below, I ended up with a catastrophic failure error in my Web part. I have seen this type of exception a couple of times and it seems that it is behaving somewhat unpredictable. Sometimes it goes, sometime not. So, the underlying cause of the exception is not at all clear. Anyone an idea?
SPWeb web = this._web.Site.AllWebs[new Guid(myGuid)];
if(web!=null)
{ ... }
OK, after some googling, I found some people with the same problem, but no real solution though. I have solved the problem by not making use of the AllWebs property. Instead I have used the OpenWeb() method and yes, the mysterious catastrophic failure does not occur anymore. But the reasons behind it are still unclear to me.
SPWeb web = this._web.Site.OpenWeb(new Guid(myGuid));
if(web!=null)
{ ... }