I just upgraded from 3.7 to 4.0 and I am now having a problem when I try to add to a child list. I changed my BusinessListBase child class to BusinessBindingListBase.
When I call parent.MyChildList.AddNew I get the following error:
System.NullReferenceException: Object reference not set to an instance of an object.
at Csla.Server.ChildDataPortal.Create(Type objectType, Object[] parameters) in C:\Visual Studio Projects\csla\40\Source\Csla\Server\ChildDataPortal.cs:line 82
at Csla.DataPortal.CreateChild[T](Object[] parameters) in C:\Visual Studio Projects\csla\40\Source\Csla\DataPortal.cs:line 824
at Csla.BusinessBindingListBase`2.AddNewCore() in C:\Visual Studio Projects\csla\40\Source\Csla\BusinessBindingListBase.cs:line 449
at System.ComponentModel.BindingList`1.System.ComponentModel.IBindingList.AddNew()
at System.ComponentModel.BindingList`1.AddNew()
at PHGT.Web.ShellSite.Areas.AdminEasyID.Controllers.ActionsController.SaveTasks(Action action, ActionViewModel vm) in D:\SVN_Main\Trunk\Source\Projects\PHGT.Web.ShellSite\Areas\AdminEasyID\Controllers\ActionsController.vb:line 172
at PHGT.Web.ShellSite.Areas.AdminEasyID.Controllers.ActionsController.Edit(ActionViewModel vm) in D:\SVN_Main\Trunk\Source\Projects\PHGT.Web.ShellSite\Areas\AdminEasyID\Controllers\ActionsController.vb:line 111
This code was all working before the upgrade and most of it is working after the upgrade. Did I miss something in the upgrade process?
CSLA 4 collection types have a default implementation for AddNewCore that invokes the child data portal. You can (and probably are) override this - but perhaps you are calling base.AddNewCore() in your override or something?
Or maybe you have a bug in your DataPortal_Create() method?
I still don't know what I am doing wrong. I am not overriding the AddNewCore. I am overriding this (we have a different way of checking rights):
Protected Overrides Sub OnAddingNew(ByVal e As System.ComponentModel.AddingNewEventArgs)
Rights.CanAddObject(_rightsObjectName, True)
e.NewObject = DataPortal.CreateChild(Of TaskGroup)()
End Sub
I can set a break point here and it is never hit before I get the exception.
This is the only code in the child dataportal create
Protected Overrides Sub Child_Create()
LoadProperty(Of Guid)(_TaskGroupIDProperty, Guid.NewGuid)
MyBase.Child_Create()
End Sub
I can set a break point here but never get there either.
The initial parent fetch works correctly and calls
Private Sub Child_Fetch(ByVal data As ITaskDto)
RaiseListChangedEvents = False
For Each dto In data.TaskGroupDtos
Dim child = DataPortal.FetchChild(Of TaskGroup)(dto)
Add(CType(child, ITaskGroupBase))
Next
RaiseListChangedEvents = True
End Sub
which fills the child list correctly. But when I call parent.Childlist.AddNew I get the exception.
Is there any thing else that you can recommend so that I can correct the problem?
From your stacktrace this is the line that failed (line 82 in ClientDataPortal.cs):
throw new Csla.DataPortalException(
"ChildDataPortal.Create " + Properties.Resources.FailedOnServer, ex, obj.Instance);
and I suspect that the execption is caused by obj being null and that there is actually another underlying exception.
Rocky has updated the ecxception handler on the 26th (after the release) so grab the latest code from the repository, compile csla and try again.
Found it. I knew the problem was not going to be csla but I just couldn't initially see the problem. Turns out that when I setup my child list class instead passing the concrete type to BusinessBindingListBase I had inadvertently passed an interface of my child object.
Thanks for the help.
Copyright (c) Marimer LLC