Problems with class properties of child objects in CSLA 3.6 Beta 1

Problems with class properties of child objects in CSLA 3.6 Beta 1

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


jmcd posted on Tuesday, October 14, 2008

I'm currently working with CSLA 3.6 Beta 1 and having a problem with business objects which contain child business objects.

I have a business object called CompanyList which inherits from BusinessBase and contains a list of Company
objects (also Business objects).  The CompanyList object has a factory method called GetCompanies which performs
a DataPortal Fetch, loading all Company business objects into the CompanyList instance.

When I call the factory method and get the instance of the CompanyList back, the Company objects have problems
with their properties (they only have two: ID and Name).  When trying to access the properties, the following exception is raised:

System.InvalidOperationException: One or more properties are not registered for this type
with inner exception System.IndexOutOfRangeException: Index was outside the bounds of the array.

When I fetch Company objects by themselves, they do not have this problem, all properties work and have the correct values.

I have spent time debugging through the framework and noticed that the Company objects have
properly working properties at the point before they are serialized before being transferred back to the client-side DataPortal.

This led me to investigate the OnDeserializedInternal method of BusinessBase which (I believe) reconstructs the properties of a Business object upon deserialization.  From the behaviour I've seen, it would appear that OnDeserializedInternal gets called for the CompanyList but not on the Company objects that are in the list that belongs to it.  

To overcome this, in CompanyList, I overrode the OnDeserializedInternal method so that it would call the OnDeserializedInternal methods of each of the items in the list of Company objects and then make a call back to the base OnDeserializedInternal method.  This raises a similar exception but it seems (from the exception stack) to be related to XML de-serialization.

Am I approaching this wrong or are there any suggestions that may help me get to the bottom of this issue?

triplea replied on Tuesday, October 14, 2008

Seems like you need to do the _dummy trick:

http://forums.lhotka.net/forums/thread/26807.aspx

jmcd replied on Tuesday, October 14, 2008

Thanks! That did the trick.

Copyright (c) Marimer LLC