From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books
I finally got to play with the latest release (cslacs-3.5.0-080222.zip is the file I've got). It looks great but I stumbled upon my first problem.I have an editable root object (Customer) which has contains an editable child object (Address). Using a Linq DAL, I fetch the Customer fields fine but when I get to the fetch part of my Address object, the first line that tries to populate a property like this:
LoadProperty<
fails with the following error: "Index was outside the bounds of the array." which gets caught in protected void LoadProperty<P>(PropertyInfo<P> propertyInfo, P newValue) and because in PropertyInfo.Index the index is -1. Now I checked another (very long) thread where a similar issue was reported but it seemed it happened for more complex scenarios. Mine is a straightforward one (I think).Apologies but I am a bit new to .Net 3.5 in general so might be doing something obviously silly here...
What does your property declaration look like?
And is your class just a concrete class with no registered properties declared in any parent classes?
Rocky
Thanks to both. I was indeed using the wrong containing type parameter so I changed it and it works fine. I now begin to understand how this can be an issue with inheritance... I havent tried it yet but was there any final solution from the previous very big thread? I know its not best practice but in a lot of occasions I have something like:
Customer : BusinessBase<Customer>GoodCustomer : CustomerBadCustomer : Customer
And use Customer to bind on a view that allows editing customers but doesnt (and shouldnt) care about the quality of the customer. That would mean that all the properties are defined in Customer but usually the validation/authorization rules are set in the conrete extended classes. Should I still register the properties in Customer with type Customer or is there a catch?
You can register your properties in a base class – against the base class type. That works fine.
The issue with inheritance is that .NET won’t necessarily initialize the static fields in your base class early enough in the process, so you need to put code in your constructor on OnDeserialized() method to set a static field (such as an integer field named _dummy or something). That forces static fields to initialize in that class and all is well.
I have a problem with LoadProperty in base class (CSLA 3.5 and 3.5.1 version). I have something like this:
public
public abstract class BaseNameDescriptionBusinessObject<T> : BaseObject<T> where T : BaseNameDescriptionBusinessObject<T>
and exception 'Property load or set failed for property Naziv (One or more properties are not registered for this type)' appeare in BaseNameDescriptionBusinessObject<T> class when use LoadProperty<string>(NazivProperty, reader.GetString("Naziv")); I try with dummy in constructor but it didn't help.
----- Original Message -----From: van To: "rocky@lhotka.net" Subject: Re: [CSLA .NET] "Index was outside the bounds of the array." error with CSLA 3.5 Beta 1Date: Tue, 30 Sep 2008 07:07:31 -0500 I have a problem with LoadProperty in base class. I have like something this: public abstract class BaseObject<T> : BusinessBase<T> public abstract class BaseNameDescriptionBusinessObject<T> : BaseObject<T> where T : BaseNameDescriptionBusinessObject<T> public class Funkcija : BaseNameDescriptionBusinessObject<Funkcija> and exception 'Property load or set failed for property Naziv (One or more properties are not registered for this type)' appeare in BaseNameDescriptionBusinessObject<T> class when use LoadProperty<string>(NazivProperty, reader.GetString("Naziv")); I try with dummy in constructor but it didn't help.
I have a problem with LoadProperty in base class. I have like something this:
I try with an override of OnDeserialized() now, but it doesn't solve the problem.
Maybe I have a some bug in my classes and there is a code:
// BaseObject<T> class
[
{
#region
}
#endregion
Uid =
LoadData(reader);
reader.Close();
db.AddInParameter(cmd,
db.ExecuteNonQuery(cmd);
// BaseNameDescriptionBusinessObject<T>
[Serializable]
_dummy = 10;
AddCustomRules();
ValidationRules.AddRule<T>(NazivPostoji,
e.Description =
protected override void LoadData(NullableDataReader reader)
try
_dummy = 20;
// Funkcija
LoadData(criteria.Value);
DataFetch(reader);
ValidationRules.CheckRules();
DoSave();
LogicalDelete(
Is there I'm doing something wrong?
van:// BaseObject<T> class [Serializable] public abstract class BaseObject<T> : BusinessBase<T>, IBusinessObjectId where T : BaseObject<T> { #region Constructor protected BaseObject() { LoadProperty<Guid>(UidProperty, Guid.Empty); } #endregion ...Is there I doing something wrong?
public abstract class BaseObject<T> : BusinessBase<T>, IBusinessObjectId where T : BaseObject<T>
#region Constructor
protected BaseObject()
LoadProperty<Guid>(UidProperty, Guid.Empty);
...
I added static field and an override of OnDeserialized() and I now have:
// BaseObject class
private
_forceInit = 5;
_forceInit = 10;
// BaseNameDescriptionBusinessObject class
protected
// Funkcija class
_forceInit = 15;
and problem still exist. Properties in the BaseObject and Funkcija classes registered properly and there is not a problem, but property Naziv and Opis in the BaseNameDescriptionBusinessObject never registered. When I go through debug, lines
private static PropertyInfo<string> NazivProperty = RegisterProperty<string>(typeof(T), new PropertyInfo<string>("Naziv", "Naziv"));
and
executed before
but it's throw an exception 'Property load or set failed for property Naziv (One or more properties are not registered for this type)'
The _forceInit code looks right. You have it in EVERY class? Base and sub?