The following Try block uses the GetWebPartCollection method, which is obsolete.
try
{
sharedWebParts =
TargetWeb.GetWebPartCollection("Default.aspx",
Microsoft.SharePoint.WebPartPages.Storage.Shared);
}
Its obsolescence and an alternative is documented here:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getwebpartcollection.aspx
The alternative: Use GetLimitedWebPartManager instead.