Managed Properties plus inheritance = Frequent errors

Managed Properties plus inheritance = Frequent errors

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


DamReev posted on Thursday, June 26, 2008

I am using CSLA 3.5 with the managed properties feature; however, I find that I run into problems when I use this along with generic inheritance. When I try and set a property that was defined and registered with a base class in a sub class CSLA bombs out in the FieldDataManager class with a IndexOutOfRangeException. It then tells me that the field is not registered on the class. I know its not registered on the class but it is registered on the subclass. Please help. I am considering the fact that FieldManager may not be fully ready for PrimeTime.

skagen00 replied on Thursday, June 26, 2008

There was a lot of discussion about this early on and a few articles available that I'm too short on time to find and then link to.

However, do the following:

In your parent classes that you descend from, include the following code in your constructor:

protected Profile()

{

   _dummy = 1;

}

_dummy is just a static integer, also in the parent class.

private static int _dummy;

Your problems will likely magically go away.

Chris

 

DamReev replied on Thursday, June 26, 2008

Wow! I walked away from my desk for a couple of minutes, and came back and there was a solution to a possible huge problem for me. Thanks! Needless to say this worked. I have to think a bit about the reason why. I thought static field initiators in base classes would get executed before the subclass constructor, but apparently not.

RockfordLhotka replied on Thursday, June 26, 2008

No, static fields initialize in a seemingly odd way - potentially long after you've made calls to instance methods and properties... Very confusing and problematic.

DamReev replied on Thursday, June 26, 2008

It seems that just putting a static constructor on my base object takes care of this as well. Just an FYI.

skagen00 replied on Thursday, June 26, 2008

This is yes, the other option that was discovered! The option using the instance constructor is slightly more performant.

RockfordLhotka replied on Thursday, June 26, 2008

There are negative performance implications to doing this. If they don’t cause you trouble, then it isn’t a problem, but you should be aware that classes with a cctor are slower to access than ones without – on every method/property call.

 

Rocky

 

From: DamReev [mailto:cslanet@lhotka.net]
Sent: Thursday, June 26, 2008 5:07 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Managed Properties plus inheritance = Frequent errors

 

It seems that just putting a static constructor on my base object takes care of this as well. Just an FYI.


William replied on Saturday, June 28, 2008

Hi Rocky,

Why classes with a cctor are slower? Especially it makes all instance method/property calls slower? Why?

Please help to advise.
Thanks.

William replied on Saturday, June 28, 2008

I think I found the reason.

http://msdn.microsoft.com/en-au/magazine/cc163857.aspx

Thanks.

Copyright (c) Marimer LLC