Problem:
One of my collegue working on custom Web Part development and got this error “Trying to use an SPWeb object that has been closed or disposed and is no longer valid” It is very common amongst developers dealing with the SharePoint object model. Here is how the error looks like”
Reason:
It is a matter of Code. The reason behind this is a silly mistake that developers do, when trying to use the SPSite/SPWeb objects. Here is the bad code that resulted in the error:
Solution:
In above code snippet, developer used “using” clause alongwith the SPContext.Current.Site which resulted in this error. It implicilty disposes the SPSite object which should not be done when using the SPContext object. Which is not ideal to use. Lets rectify the code a little bit and have a look at the good code snippet which resolved this issue:
Noteworthy:
After removing the “using” clause from the SPContext.Current.Site code works fine!
Same thing applies when try to dispose either explicitly/implicitly the SPContext.Current.Web object.
So, NEVER dispose SPContext objects either implicitly pulling the “using” clause or explicitly by “using” Dispose method from “Finally” block.
Nice blog here! Also your website loads up fast!
What web host are you using? Can I get your affiliate link to your host?
I wish my site loaded up as fast as yours lol
My homepage http://www.Bradmcallister.com
great post, very informative. I’m wondering why the opposite experts
of this sector don’t realize this. You should continue your writing.
I am sure, you’ve a huge readers’ base already!
My website professional web design company london
Thank you for sharing your thoughts. I really appreciate your efforts and I will be waiting for your next post
thanks once again.
My webpage – web development agency in london
You need to be a part of a contest for one of the best blogs on the
web. I’m going to highly recommend this blog!
My site https://www.Bradmcallister.com
Hello, I enjoy reading all of your article post. I wanted
to write a little comment to support you.
Here is my webpage … London Web Designer
Keep on working, great job!
Look at my blog post – https://Www.bradmcallister.Com/
Howdy would you mind letting me know which
hosting company you’re utilizing? I’ve loaded your blog in 3 different
internet browsers and I must say this blog loads a lot quicker then most.
Can you recommend a good hosting provider at a reasonable price?
Thanks, I appreciate it!
Feel free to surf to my webpage; website developers near me