I'm trying to figure out what could be causing this exception, but I don't understand why/how RegisterProperty is getting called to be causing this. I'm using Csla 3.8 beta....
Can not register property <<Object PropertyName>> after containing type <<Object ClassName>> has been instantiated
at Csla.Core.FieldManager.PropertyInfoManager.RegisterProperty[T](Type objectType, PropertyInfo`1 info) in C:\Projects\Local\csla3.8.0beta\cslacs\Csla\Core\FieldManager\PropertyInfoManager.cs:line 68
at Csla.BusinessBase`1.RegisterProperty[P](PropertyInfo`1 info) in C:\Projects\Local\csla3.8.0beta\cslacs\Csla\BusinessBase.cs:line 422
at Csla.BusinessBase`1.RegisterProperty[P](Expression`1 propertyLambdaExpression, String friendlyName) in C:\Projects\Local\csla3.8.0beta\cslacs\Csla\BusinessBase.cs:line 467
at BinaryXmlBenchmark.Library.TestCrit..ctor() in C:\Projects\Local\BinaryXmlBenchmark\BinaryXmlBenchmark.Library.Server\TestCrit.cs:line 11
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
This exception was added a while back (3.6.3?) to overcome a common bug people were encountering with RegisterProperty().
If you use the RegisterProperty() overload where you provide the containing type as the first parameter, you are very subject to copy-paste errors where the containing type isn't actually the right type.
I recommend avoiding that overload in all cases except CommandBase and CriteriaBase subclasses where you can't avoid it. Instead use the generic overload that infers the correct type.
In short - you have a RegisterProperty() call where you are providing the incorrect type as the first parameter and you need to fix that type.
That's what's odd, My rather simple class uses the lambda expression overload.
aw crap.... I just now saw my problem after I pasted this.... my property info isn't static. That's what I get for being in a hurry. Thanks for the help!
using
System;using
Csla;using
Csla.Serialization;namespace
BinaryXmlBenchmark.Library{
[
Serializable()] public class TestCrit : Csla.BusinessBase<TestCrit>{
//register properties protected PropertyInfo<int> PacketAmountProperty = RegisterProperty<int>(c => c.PacketAmount, "PacketAmount"); public int PacketAmount { get { return GetProperty(PacketAmountProperty); } set { SetProperty(PacketAmountProperty, value); }}
#if
SILVERLIGHTpublic TestCrit() { }
#else
private TestCrit() { }#endif
}
}
Copyright (c) Marimer LLC