Object reference not set to an instance of an object error in SharePoint
Object reference not set to an instance of an object is one of the generic and common in SharePoint, specially has been raised while working with List and libraries. Also it could raise while working with web part. The basic cause is the reference the object is not able to trace out by the SharePoint object mode.
Let me share with one simple example from event receiver perspective. I have written a simple event receiver in SharePoint where I’m selecting the value from a list column (i.e. Tipologi KPI in this example).
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
string CategoryName = string.Empty;
try
{
CategoryName = properties.AfterProperties["Tipologi KPI"].ToString();
}
catch (Exception ex)
{
properties.ErrorMessage = ex.Message.ToString();
properties.Cancel = true;
}
…..
I got the following error at very initial.
Object reference not set to an instance of an object. at Microsoft.SharePoint.Library.SPRequestInternalClass.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage)
at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage)
Started debugging and again found the error at line properties.AfterProperties["Tipologi KPI"].ToString()
I have tried to using the following way.
SPList _List = properties.OpenWeb().Lists[properties.ListTitle];
SPListItem item = _List.GetItemById(properties.ListItemId);
CategoryName = item["Tipologi KPI"].ToString();
Same error has been occurred (custom error).
Server Error in ‘/’ Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Object reference not set to an instance of an object.
Source Error:
|
|
Stack Trace:
[COMException (0x81020089): Object reference not set to an instance of an object.]
Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +0
Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +411
[SPException: Object reference not set to an instance of an object.]
Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +534
Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents) +3021
Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +682
Microsoft.SharePoint.SPListItem.UpdateOverwriteVersion() +182
Microsoft.SharePoint.WebControls.SaveButton.SaveItem(SPContext itemContext, Boolean uploadMode, String checkInComment) +256
Microsoft.SharePoint.WebControls.SaveButton.SaveItem() +104
Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +476
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
|
Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4016
While rechecking the code with column name, I found the typo mistake the column name should be Tipologia KPI instead of Tipologi KPI( one a was not there in the column reference). Rebuild the solution and this time it worked.
This error could be occured due to existing of multiple DLL in the GAC (may be for release and debug) by same name. In this case, remove the DLL from GAC and do a fresh build and place the new DLL in GAC. Make sure you reset the IIS (start >> run >> resetIIS) before trying again.
Please note, this error is not for list and libraries, as I said at the begining, the root cause is reference not found. So there could be multiple reasons behind this and as a consiquence there would be multiple solutions for different reasons as well. I have face this error for the above mentioned problem and get the resolutions by folloing the steps. Hope this will help you.
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
string CategoryName = string.Empty;
try
{
CategoryName = properties.AfterProperties["Tipologi KPI "].ToString();
}
catch (Exception ex)
{
properties.ErrorMessage = ex.Message.ToString();
properties.Cancel = true;
}



I’d come to concede with you one this subject. Which is not something I usually do! I enjoy reading a post that will make people think. Also, thanks for allowing me to comment!
After read a couple of the blog posts on your web site since yesterday, and I truly like your style of blogging. I added it to my favorites website list and will be checking back soon. Please check out my internet site too and let me know your thought.
Good point, though sometimes it’s hard to arrive to definite conclusions
Thank you for another great story. I’m really glad I was able to find this article. Has anyone else has a similar experience to the OP
hechizos
I’m not able to enjoy this site correctly on safari I believe there’s a issue.
I got what you intend, saved to bookmarks , very decent web site .
Of course, what a fantastic blog and revealing posts, I surely will bookmark your website.All the Best!
Awsome article and straight to the point. I am not sure if this is really the best place to ask but do you guys have any ideea where to get some professional writers? Thanks
You own a enormously interesting web page covering lots of topics I am interested as well.Just bookmarked your weblog so I can figure out more in the next days… Just continue your marvellous artice writing
I want to thank you for the time you have made in writing this blogpost. I am hoping the same top-quality blog post from you in the upcoming as well. In fact your creative writing skill has inspired me to begin my own blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine model of it.
I have study a few of the articles on your site since yesterday, and I really like your way of blogging. I bookmarked it to my favorites blog list and will be checking back soon. Please check out my internet site as well and let me know your thought.
Do you people have a twitter fan page for SharePoint Himadrish » Object reference not set to an instance of an object error in SharePoint? I looked for for one on facebook but could not discover one, I would really like to become a fan!
Heya i’m for the first time here. I found this board and I find It really useful & it helped me out a lot. I hope to give something back and aid others like you helped me.
Very sensible question, comment and a solution from which, I have realized one thing today.
Well I definitely liked studying it. This article provided by you is very useful for correct planning.
Whats up, what an excellent knowledge in your site here SharePoint Himadrish » Object reference not set to an instance of an object error in SharePoint Regards, Jeffry Kaye
Noticed your internet page on del.icio.us today and genuinely loved it.. i saved it and will likely be back to check it out some a lot more later .. As a Noob, I’m often searching for on-line for posts which will assist me. Very best wishes!
I think you have observed some very interesting details , thanks for the post.
You made some nice points there. Thank you for the good post!
Thanks… good discussion. Appreciate the info.
Great post. Thanks for the insight. Much appreciated.
Hello my friend! I wish to say that this post is amazing, nice written and include almost all vital infos. I would like to see more posts like this .
Your blog always makes me think, I have just bookmarked it!
I am impressed with this website , real I am a fan .
Youre so cool! I dont suppose Ive read anything like this before. So nice to discover somebody with some original thoughts on this subject. realy thank you for starting this up. this website is something that is required on the internet, somebody with a little originality. useful job for bringing some thing new to the web!
Thanks friend. That is cool knowing
Thanks dude. It is nice seeing
some truly superb articles on this internet site , appreciate it for contribution.
Hi, what an excellent facts in your web-site listed here %BLOGTITLE% Regards, Matt Stallone
i have begun to visit this cool site a couple of times now and i have to say that i find it quite nice actually. keep it up! :p
You completed a number of good points there. I did a search on the topic and found mainly folks will go along with with your blog.
Great post. I appreciate you taking the time to write this. I bookmarked your blog. Thanks
You can definitely see your enthusiasm in the work you write. The world hopes for even more passionate writers like you who aren’t afraid to say how they believe. Always go after your heart.
you have brought up a very good points , thankyou for the post.
I agree with your details , excellent post.
I am glad to be a visitant of this unadulterated web site! , appreciate it for this rare info ! .
I really like your writing style, fantastic information, regards for posting : D.
Enjoyed the read, went well with my night cap.
I’d come to cut a deal with you one this subject. Which is not something I typically do! I enjoy reading a post that will make people think. Also, thanks for allowing me to comment!
Usually I do not post on blogs, but I would like to say that this article really forced me to do so! Thanks, really nice article.
I don’t even know how I got here, but I thought this post was good. Cheers!
Awesome Blog. I add this Post to my bookmarks.
Excellent! Your site has a bunch comments. How did you get all of these people to see your post I’m jealous! I’m still studying all about posting information on the internet. I’m going to view pages on your site to get a better understanding how to attract more people. Thanks! http://www.tokyoexodus.com
Thanks Cara.
Yes, I do have facebook account and it is by my name.