Object reference not set to an instance of an object error in SharePoint

August 7th, 2009 | Categories: Troubleshoot Issues | Tags:

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

Object reference not set to an instance of an object


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()

Server Error Object Reference Not Set

Server Error Object Reference Not Set

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


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;

}

  1. :-) cool!

  2. November 15th, 2010 at 06:09

    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!

  3. December 8th, 2010 at 22:02

    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.

  4. December 9th, 2010 at 08:03

    Good point, though sometimes it’s hard to arrive to definite conclusions

  5. December 9th, 2010 at 08:23

    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

  6. December 14th, 2010 at 04:02

    I’m not able to enjoy this site correctly on safari I believe there’s a issue.

  7. December 15th, 2010 at 06:26

    I got what you intend, saved to bookmarks , very decent web site .

  8. December 17th, 2010 at 21:14

    Of course, what a fantastic blog and revealing posts, I surely will bookmark your website.All the Best!

  9. December 17th, 2010 at 23:26

    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 :)

  10. December 21st, 2010 at 16:00

    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

  11. December 24th, 2010 at 16:07

    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.

  12. December 25th, 2010 at 16:51

    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.

  13. January 9th, 2011 at 03:59

    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!

  14. January 14th, 2011 at 02:15

    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.

  15. January 16th, 2011 at 10:27

    Very sensible question, comment and a solution from which, I have realized one thing today.

  16. January 19th, 2011 at 10:12

    Well I definitely liked studying it. This article provided by you is very useful for correct planning.

  17. January 20th, 2011 at 22:08

    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

  18. January 21st, 2011 at 13:20

    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!

  19. January 25th, 2011 at 04:09

    I think you have observed some very interesting details , thanks for the post.

  20. January 26th, 2011 at 01:09

    You made some nice points there. Thank you for the good post!

  21. January 27th, 2011 at 22:25

    Thanks… good discussion. Appreciate the info.

  22. January 27th, 2011 at 23:22

    Great post. Thanks for the insight. Much appreciated.

  23. February 3rd, 2011 at 08:07

    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 .

  24. February 4th, 2011 at 05:25

    Your blog always makes me think, I have just bookmarked it!

  25. February 4th, 2011 at 14:14

    I am impressed with this website , real I am a fan .

  26. February 4th, 2011 at 22:39

    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!

  27. February 5th, 2011 at 23:26

    Thanks friend. That is cool knowing

  28. February 6th, 2011 at 14:35

    Thanks dude. It is nice seeing

  29. February 7th, 2011 at 15:08

    some truly superb articles on this internet site , appreciate it for contribution.

  30. February 7th, 2011 at 22:43

    Hi, what an excellent facts in your web-site listed here %BLOGTITLE% Regards, Matt Stallone

  31. February 8th, 2011 at 03:10

    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

  32. February 8th, 2011 at 14:15

    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.

  33. February 9th, 2011 at 20:40

    Great post. I appreciate you taking the time to write this. I bookmarked your blog. Thanks :)

  34. February 10th, 2011 at 06:35

    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.

  35. February 10th, 2011 at 08:40

    you have brought up a very good points , thankyou for the post.

  36. February 11th, 2011 at 05:31

    I agree with your details , excellent post.

  37. February 11th, 2011 at 06:40

    I am glad to be a visitant of this unadulterated web site! , appreciate it for this rare info ! .

  38. February 11th, 2011 at 09:03

    I really like your writing style, fantastic information, regards for posting : D.

  39. February 12th, 2011 at 01:49

    Enjoyed the read, went well with my night cap.

  40. February 12th, 2011 at 07:18

    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!

  41. March 3rd, 2011 at 19:22

    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.

  42. March 17th, 2011 at 04:46

    I don’t even know how I got here, but I thought this post was good. Cheers!

  43. March 17th, 2011 at 22:59

    Awesome Blog. I add this Post to my bookmarks.

  44. March 18th, 2011 at 16:37

    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

  45. Himadrish
    December 25th, 2010 at 05:58

    Thanks Cara.

    Yes, I do have facebook account and it is by my name.

7 trackbacks

  1. Hampton Roads Listings Trackback | 2011/07/21
  2. Yoshol Trackback | 2011/09/24
  3. CristaD Trackback | 2011/10/15
  4. doors Trackback | 2011/10/16
  5. red bull Trackback | 2011/11/08
  6. Minecraft Texture Packs Trackback | 2011/11/19
  7. IFRS Trackback | 2012/01/12
You must be logged in to post a comment.