I had a project where I had defined several managed paths with a wildcard inclusion. Via a WebService, there were SiteCollections provisioned under these managed paths and in the RootWeb of the Root Site Collection of the Web Application, I stored a list of references (urls) to these Site Collections. Sometimes the provisioning was taking quite long and the caller of the WebService received a timeout. So I let him send me a unique identifier and stored this also in the list of references. When he called again, I checked that list with a CAML query to avoid duplicated provisionings. But with the url and the below code, I always got a nasty error message: “The site X could not be found in the Web application SPWebApplication Name=Y Parent=SPWebService”. And I was pretty sure it was there.

SPSite site = New SPSite(urlOfSiteCollection);

So I looked at the overloads and noticed you can pass a Guid as well. Changed the reference list to store the id of the Site Collection and changed my code into:

SPSite site = New SPSite(idOfSiteCollection);

Gone was the error message and it worked.

My opinion, when you have to store information of a SiteCollection, so you can use it later on to rebuild a SPSite object, you better use the id (Guid) instead of the url (String).