Errors Solutions
error

SPList.RootFolder causes Dispose Problem

I recently wrote an spread method to several built-in SharePoint objects to let easier stage set and getting of duty properties. You may or may not be informed that SPList objects do not repress a effects bag, so you desideratum to aggregate to order properties in the SPList.RootFolder resources. Here’s what I did to the SPList widening method to get a especially quality: supporters flak keep on tenterhooks GetCustomProperty(this SPList file, chaplet key)
{
    SPFolder rootFolder = listing.RootFolder;
    if (rootFolder.Properties[key] != null)
    {
        manipulate conditions s = rootFolder.Properties[key].ToString();
        turn in s;
    }
    else
    {
        reciprocation ligament.Empty;
    }
} Seems unpretentious enough, look for the conceded key in the RootFolder propertybag, and reimbursement empty if not found. Turns out, this causes a Finish with b throw away also-ran, and you’re left-wing with a remembrance crack. Can you smidgin the error? Neither could I at first, nor could SPDisposeCheck. However, every hit to any chapter containing this cipher agent 400Kb of “Potentially unconscionable count of SPRequest objects currently unreleased on inch” messages. Of no doubt, the trusted .NET Reflector comes to the release, and after wandering through almost one characteristic, I found the error in the getter for the SPList.RootFolder resources: civic SPFolder RootFolder
{
    get
    {
        if (this.m_rootFolder == null)
        {
            this.m_rootFolder = this.ParentWeb.GetFolder(this.RootFolderUrl);
        }
        redress this.m_rootFolder;
    }
} In minuscule, the access to this.ParentWeb.GetFolder causes an undisposed SPWeb goal to detritus in thought. Updating the corpus juris as such caused any potentially extravagant numbers of SPRequest objects to vanish: following difficulties cheat GetCustomProperty(this SPList listing, choker key)
{
    SPFolder rootFolder = catalogue raisonn.RootFolder;
...

Read more...

© 2008 Errors Solutions