Do you know to never dispose objects from SPContext.Current?
Updated by Brady Stroud [SSW] 1 year ago. See history
123
Disposing objects in SharePoint is important, but never do it with objects from SPContext.Current
. SharePoint will manage disposing these objects itself.
<figureEmbed figureEmbed={{ preset: "badExample", figure: 'Figure: Using statement is trying to dispose current site object - it will cause exception', shouldDisplay: true } } />using (SPWeb web = SPContext.Current.Site.RootWeb){//do something here}
Just simply use "Current" object directly.
<figureEmbed figureEmbed={{ preset: "goodExample", figure: 'Figure: Use Current objects directly - don\'t need to dispose them', shouldDisplay: true } } />SPWeb web = SPContext.Current.Site.RootWeb;//do something here
Related rules
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.