This is a migrated thread and some comments may be shown as answers.

Looking for an explanation

2 Answers 28 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 18 Jul 2010, 05:12 PM
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."
  Source="Telerik.OpenAccess.Runtime"
  StackTrace:
       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.

-- 
Stuart

2 Answers, 1 is accepted

Sort by
0
Accepted
Thomas
Telerik team
answered on 19 Jul 2010, 08:31 AM
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
http://www.telerik.com/community/code-library/orm/general/best-practices-in-web-development-with-openaccess.aspx
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,
Thomas
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
0
Stuart Hemming
Top achievements
Rank 2
answered on 19 Jul 2010, 08:40 AM
Thanks a lot Thomas.

-- 
Stuart
Tags
General Discussions
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Thomas
Telerik team
Stuart Hemming
Top achievements
Rank 2
Share this question
or