This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Guys I'm getting the following exception when validating an entity that has an address value object with a string field set to not nullable and validate presence set to true: Unable to cast object of type 'System.ComponentModel.PropertyChangedEventHandler' to type 'System.String'.
at Mindscape.LightSpeed.Model.FieldModel.HasDefaultValue(Entity ) at Mindscape.LightSpeed.Validation.ValidationContext.get_TargetValueIsDefault() at Mindscape.LightSpeed.Validation.PresenceValidationRule.Validate(ValidationContext validationContext) at Mindscape.LightSpeed.Model.FieldModel.Validate(ValidationContext , ICollection`1 ) at Mindscape.LightSpeed.Model.ValueObjectFieldModel.Validate(ValidationContext , ICollection`1 ) at Mindscape.LightSpeed.Model.TypeModel.(IUnitOfWork , Entity , ICollection`1 ) at Mindscape.LightSpeed.Entity.Validate(ICollection`1 ) at Mindscape.LightSpeed.Entity.Validate() at Mindscape.LightSpeed.Entity.get_IsValid() This exception does not occur for entities (with non nullable string fields and validate presence set) - just value objects. If I switch validate presence to false the exception goes away. In the meantime I am working around this by perfoming this validation in the OnValidate override of every entity using the address value object. I have tried a range of builds including the latest nightly build with the same result. Can you please confirm this is a bug or am I missing something? |
|
|
Hmm, while I haven't been able to reproduce this exactly, I think it is a symptom of a more general bug I found while looking for it. That bug will be fixed in the next nightly build and it should resolve the issue you're seeing -- if not, could you provide us with an entity and value object class that exhibit the problem for you? Thanks! |
|
|
is that more general bug you've fixed also likely to produce something like this? 2011-06-10 12:36:49.5057 | ERROR | MyService | 21 | Object reference not set to an instance of an object. | System.NullReferenceException: Object reference not set to an instance of an object.
I'm getting errors trying to save what looks like exactly the same thing - valueobject with non-nullable presence-required strings. cheers |
|
|
just in case you're still looking at this - generally getting problems with presence-required on valueobject properties. regardless of type, if i set presence-required it all blows up with either null ref exceptions (string properties) or validation errors (for integral types) where there clearly is a value provided... |
|
|
The bug I found and fixed could give you all sorts of weird errors. So I think these are manifestations of the same underlying bug, and should therefore be fixed in the next nightly build. If you're still seeing these problems after that, let us know and we'll take another look. |
|
|
Many thanks Ivan, this fix did the trick. All is good. Apologies for the delay in getting back to you. Cheers |
|