SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

SPDispose gives error Disposable type not disposed Microsoft.SharePoint.SPSite ***This may be a false positive depending on how the type was created or if it is disposed outside the current scope when run with eleveted privilage is used. here is the code:

                SPWebApplication webAppContext = properties.Feature.Parent as SPWebApplication;

                site = webAppContext.Sites[0];
                userToken = site.SystemAccount.UserToken;
            /* End: 003 */
            /* Start: 001 */
         using (SPSite siteColl = new SPSite(site.ID, userToken))

                SPWebApplication webApp = siteColl.WebApplication;
                if (null != webApp)
                    if (webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, Constant.customAccessDeniedPage))
share|improve this question
Please provide us with some code. On which row are you getting this Error/Warning. – RBDev Aug 24 '12 at 9:32
keeping site inside runWithElevated is not affecting anyway. stil gettin same error. – user10513 Sep 4 '12 at 5:44

I would expect that this error is not from within the "using" part, but from the site = webAppContext.Sites[0]; above.

Where is "site" appearing the first time? Do you really need this outside the elevatedPrivilegues-Part?

share|improve this answer
its the first time only. if i declare it inside elevatedPrivilages then it cant be identified inside using..:( – pallavi Aug 27 '12 at 7:21
But if I see that right, you only need the ID. Why not save this in an extra variable and keep "site" inside the runElevated scope? – Ole Albers Aug 29 '12 at 7:31

This kind of error generally comes when you have created an SPSite object and passed it to a function. The object is disposed inside the function and hence the calling function doesnt dispose the object. This error can also occur in the reverse condition where a function returns an SPSite/SPWeb object and the caller takes care of disposing of the object. Any other similar situations can also results with such errors.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.