"CSLA.DataPortalException: ChildDataPortal.Fetch failed on the server" with CSLA 3.6.3

"CSLA.DataPortalException: ChildDataPortal.Fetch failed on the server" with CSLA 3.6.3

Old forum URL: forums.lhotka.net/forums/t/8280.aspx


AnandSuresh posted on Monday, January 04, 2010

I have a BO that has 3 Child Collections. When I run the web-page, it works fine and displays the list of BOs. However when I click on the edit button for a BO, I receive the error:

"CSLA.DataPortalException:  ChildDataPortal.Fetch failed on the server"

This is thrown when the code tries to call the Child_Fetch function to retrieve the data for child collection.

Now the interesting part (read "part-that-makes-you-wanna-pull-your-hair-out"):
After a lot of tracing and debugging, I managed to find the exact line that causes the error to be thrown!

During the execution of the ChildDataPortal.Fetch() function, the code creates an instance of the business object using the LateBoundObject class, which in turn uses MethodCaller to execute the constructor for the Child Object.

The constructor I have used in the child is:

Private Sub New()
End Sub

The error gets throw when the constructor is called. I seem to have run out of tests and explanations for this!


Any help is highly appreciated! Also please let me know what specific pieces of code you would need to diagnose the error.

Andy

RockfordLhotka replied on Monday, January 04, 2010

What is the actual exception that occurs? This would be the .BusinessException value on the DataPortalException you get on the client.

AnandSuresh replied on Monday, January 04, 2010

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 116:          ' ignore exceptions from the exception handler
Line 117: End Try
Line 118: Throw New Csla.DataPortalException("ChildDataPortal.Fetch " & My.Resources.FailedOnServer, ex, obj.Instance)
Line 119: End Try
Line 120:

Source File: D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Server\ChildDataPortal.vb    Line: 118

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
Csla.Server.ChildDataPortal.Fetch(Type objectType, Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Server\ChildDataPortal.vb:118
Csla.DataPortal.FetchChild(Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\DataPortal.vb:895
BusinessLogic.CruiseVessel.Retrieve(ProductCruise Cruise, Vessel Vessel) in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\CruiseVessel.vb:275
Read_CruiseVessel(ObjectMaterializer`1 ) +212
System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +29
Csla.Core.ExtendedBindingList`1.AddRange(IEnumerable`1 range) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Core\ExtendedBindingList.vb:101
BusinessLogic.CruiseVesselList.Child_Fetch(Guid CruiseID) in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\CruiseVesselList.vb:57
dm(Object , Object[] ) +68
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Reflection\MethodCaller.vb:269

[CallMethodException: Child_Fetch method call failed]
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Reflection\MethodCaller.vb:274
Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Reflection\MethodCaller.vb:201
Csla.Reflection.LateBoundObject.CallMethod(String method, Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Reflection\LateBoundObject.vb:90
Csla.Server.ChildDataPortal.Fetch(Type objectType, Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Server\ChildDataPortal.vb:91

[DataPortalException: ChildDataPortal.Fetch failed on the server]
Csla.Server.ChildDataPortal.Fetch(Type objectType, Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\Server\ChildDataPortal.vb:118
Csla.DataPortal.FetchChild(Object[] parameters) in D:\Projects\Test Source Code\CSLA.NET 3.6.3 in VB.NET\Csla\DataPortal.vb:895
BusinessLogic.CruiseVesselList.GetList(ProductCruise Cruise) in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\CruiseVesselList.vb:17
BusinessLogic.ProductCruise.get_Vessels() in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\ProductCruise.vb:98
ProductManagement.grdVessels_RowDataBound(Object sender, GridViewRowEventArgs e) in D:\Projects\Project Source Code\GatewayClipper.com\Administration\ProductManagement.aspx.vb:456
System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e) +108
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +167
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +227
Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) +821
Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls) +129
Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +574
Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +495
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
Telerik.Web.UI.GridTableView.PerformSelect() +4
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
Telerik.Web.UI.GridTableView.DataBind() +235
Telerik.Web.UI.GridTableView.Rebind() +48
Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +159
Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +134
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +115
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4016

RockfordLhotka replied on Monday, January 04, 2010

Can you try compiling your code against the C# version of CSLA .NET? The VB version is for reference only, and doesn't get the same level of broad use (and therefore testing) as the official release.

AnandSuresh replied on Monday, January 04, 2010

Still the same.... no luck! Messes up at exactly the same point..... the child BO constructor call.


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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 140:          // ignore exceptions from the exception handler
Line 141: }
Line 142: throw new Csla.DataPortalException(
Line 143: "ChildDataPortal.Fetch " + Properties.Resources.FailedOnServer, ex, obj.Instance);
Line 144: }

Source File: D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Server\ChildDataPortal.cs    Line: 142

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
Csla.Server.ChildDataPortal.Fetch(Type objectType, Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Server\ChildDataPortal.cs:142
Csla.DataPortal.FetchChild(Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\DataPortal.cs:921
BusinessLogic.CruiseVessel.Retrieve(ProductCruise Cruise, Vessel Vessel) in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\CruiseVessel.vb:275
Read_CruiseVessel(ObjectMaterializer`1 ) +433
System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +29
Csla.Core.ExtendedBindingList`1.AddRange(IEnumerable`1 range) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Core\ExtendedBindingList.cs:103
BusinessLogic.CruiseVesselList.Child_Fetch(Guid CruiseID) in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\CruiseVesselList.vb:57
dm(Object , Object[] ) +66
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Reflection\MethodCaller.cs:342

[CallMethodException: Child_Fetch method call failed]
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Reflection\MethodCaller.cs:351
Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Reflection\MethodCaller.cs:260
Csla.Server.ChildDataPortal.Fetch(Type objectType, Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Server\ChildDataPortal.cs:116

[DataPortalException: ChildDataPortal.Fetch failed on the server]
Csla.Server.ChildDataPortal.Fetch(Type objectType, Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\Server\ChildDataPortal.cs:142
Csla.DataPortal.FetchChild(Object[] parameters) in D:\Projects\Test Source Code\CSLA 3.7.1 in C#\cslacs\Csla\DataPortal.cs:921
BusinessLogic.CruiseVesselList.GetList(ProductCruise Cruise) in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\CruiseVesselList.vb:17
BusinessLogic.ProductCruise.get_Vessels() in D:\Projects\Project Source Code\GatewayClipper.com\App_Code\BusinessLogic\ProductCruise.vb:98
ProductManagement.grdVessels_RowDataBound(Object sender, GridViewRowEventArgs e) in D:\Projects\Project Source Code\GatewayClipper.com\Administration\ProductManagement.aspx.vb:456
System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e) +108
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +167
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +387
Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) +979
Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls) +187
Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1077
Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +782
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
Telerik.Web.UI.GridTableView.PerformSelect() +28
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
Telerik.Web.UI.GridTableView.DataBind() +364
Telerik.Web.UI.GridTableView.Rebind() +98
Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +395
Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +165
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4016

RockfordLhotka replied on Monday, January 04, 2010

It looks to me like this stack trace shows the error occuring inside the Child_Fetch() method - something to do with the System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() call.

If it is inside Child_Fetch(), then it is actually after the child object instance was created.

AnandSuresh replied on Wednesday, January 06, 2010

Hey Rocky,

Sorry for the delay in the response. Took me while to test it, but its still failing at the constructor.

Here is a sequence of events.... maybe this might help.
        Private Shared propVessels As PropertyInfo(Of CruiseVesselList) = RegisterProperty(New PropertyInfo(Of CruiseVesselList)("Vessels", "Cruise Vessels"))
        Public ReadOnly Property Vessels() As CruiseVesselList
            Get
                'Check if the list already exists
                If Not FieldManager.FieldExists(propVessels) Then
                    If IsNew Then
                        LoadProperty(Of CruiseVesselList)(propVessels, CruiseVesselList.NewList)
                    Else
                        LoadProperty(Of CruiseVesselList)(propVessels, CruiseVesselList.GetList(Me))
                    End If
                End If

                'Return the data
                Return GetProperty(Of CruiseVesselList)(propVessels)
            End Get
        End Property

        Private Overloads Sub Child_Fetch(ByVal CruiseID As Guid)
            'Retrieve the cruise object
            Dim Cruise As ProductCruise = ProductCruise.Retrieve(CruiseID)
            If Cruise Is Nothing Then Exit Sub

            'Disable list events
            RaiseListChangedEvents = False

            'Open the data connection
            Using ctx = Csla.Data.ContextManager(Of DataAccess.DataContextName).GetManager("ConnectionString")
                'Read the data
                Dim data = From Record In ctx.DataContext.ProductCruiseVessels Select Record Where Record.CruiseID = CruiseID Select CruiseVessel.Retrieve(Cruise, Vessel.Retrieve(Record.VesselID))

                'Add the data to the list
                Me.AddRange(data)
            End Using

            'Enable list events
            RaiseListChangedEvents = True
        End Sub

The AddRange function is where it starts to break.
This is the sequence of events.

Once the error is thrown, I click F5 to refresh the page, and I again receive the error..... but this time, its not the 1st Child Collection (CruiseVesselList)! But its the 3rd Child Collection..... failing at the exact same point, in exactly the same way.

Another F5 click and the code runs normally..... until the app-domain is restarted.

I am out of tests and ideas as to what could be causing this problem.... I use the ProjectTracker Sample Code as a guide for writing my business objects.

Any thoughts?


RockfordLhotka replied on Thursday, January 07, 2010

All I can suggest at this point is that you put a breakpoint in the CSLA code where it is creating the instance of your type and use the debugger to identify what value is null.

The thing is, in the past 18-24 months of this code existing no one else has encountered this issue, so there's something entirely unique about your scenario. Maybe it is the use of LINQ, maybe your object's constructor is running some code - hard to say.

AnandSuresh replied on Sunday, January 10, 2010

Hey Rocky,

Finally got it working!!!! :)

Took your advice and tested with breakpoints in CSLA (after going through just about every version from CSLA 3.6.3 to 3.8.1).

Turns out that the error was in the AddBusinessRules() function of my BB class. I was calling the object's Parent property in the child class, which was throwing the NullReferenceError.

What I don't understand is how/why it was throwing the NullReferenceException only when the AppDomain was recycled. The following requests worked perfectly fine.

It seemed to happen only the first time the object was instantiated and then worked fine until the AppDomain was recycled. Something to do with the way CSLA caches object data?

Thanks for the assistance.

Copyright (c) Marimer LLC