Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My current development environment is SharePoint 2010. I am writing some code on feature activated event in my event receiver. Idea is to add some web parts on the page through code.

Here is the example code

using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(pageUrl,   WCWP.PersonalizationScope.Shared))
    {
      try
      {
       manager.AddWebPart(,,,,,);
       manager.SaveChanges(...);
      }
      catch(Exception ex)
      {
      }         
    }

There are no issues in the code and the purpose it intends to accomplish. When I run MSOCAF for my solution it complains about code above, that "GetLimitedWebPartManager" returns SPWeb object and it should be disposed explicitly. The solution it suggests is

finally
{
manager.Web.dispose();
}   

even after disposing the Web property of my object MSOCAF is still reporting the same error.

Any suggestions will be of great help.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.