Looking for an explanation

Thread is closed for posting
3 posts, 1 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 18 Jul 2010 Link to this post

    I have spent a little time tracking down an error with my code.

    The error occurred when trying to commit changes made to an object instance to the database. The error reported is reproduced here:
    System.NullReferenceException was unhandled by user code
      Message="Object reference not set to an instance of an object."
           at OpenAccessRuntime.DataObjects.PCStateMan.setStringField(PersistenceCapable _pc, Int32 field, String currentValue, String newValue)
           at RSD.Model.Location.OpenAccessEnhancedSetname(Location , String )
           at RSD.Model.Location.set_Name(String value) in C:\Users\Stuart\Documents\Visual Studio 2008\Projects\RSD.Model\Location.cs:line 98
           at RSD.Website.Controls.LocationDetailsView.PopulateLocation() in c:\Users\Stuart\Documents\Visual Studio 2008\WebSites\RSD\Controls\School\LocationDetailsView.ascx.cs:line 156
           at RSD.Website.Controls.LocationDetailsView.dv_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e) in c:\Users\Stuart\Documents\Visual Studio 2008\WebSites\RSD\Controls\School\LocationDetailsView.ascx.cs:line 120
           at System.Web.UI.WebControls.DetailsView.OnItemUpdating(DetailsViewUpdateEventArgs e)
           at System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation)
           at System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
           at System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e)
           at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
           at System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e)
           at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
           at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
           at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Now, I discovered that the problem appeared to be of my making. I was getting something back from the DB then, in an effort to cut down on the number of DB accesses, I was saving the object in my session state then, later, I was getting the item back from the Session, updating the values and attempting to write them back.

    I assume that in saving the object to, or reading it back from, Session that some link to something in OA has been broken. There were no nulls in any of the objects in my code, so I have to assume that the OA elves somehow lost their way.

    More for information than anything else, I'd love to hear why this happens.

  2. Answer
    Thomas avatar
    590 posts

    Posted 19 Jul 2010 Link to this post

    Hello Stuart,

    very likely you are trying to set a string value on an object that was 'detached' from the database by means of serialization into your session state. OpenAccess uses lazy loading, and that is implemented by help of a 'state manager' instance. This state manager instance is not serializable (by intention).
    I think you should have a look into this article
    which explains some patterns that could be used with web development. In addition, I think the ideas from the article http://www.telerik.com/community/code-library/orm/general/using-telerik-openaccess-orm-persistent-objects-in-web-scenarios-on-multiple-pages.aspx show you how to hold persistent data in the session state.

    Kind regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 19 Jul 2010 Link to this post

    Thanks a lot Thomas.

Back to Top