Deactivates validation on deserialisation

Mar 29, 2012 at 7:08 AM
Edited Mar 29, 2012 at 8:44 AM

Hi,

First, thanks for the great tool. I can serialise and deserialise data in silverlight. No problem with that. But once I load the file in, non of the validation on the objects and properties work. I store the objects in static class in the form of Dictionary<string, Dictionary<string,object> and then serialise the class.

Is there anything I should consider that prevents this?

Just need to mention that custom validation is not working. These were decorated in the public property.

The csutom valiation looks something like:

    public class MyValidationAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            bool valid = false;
            if (items != null)
            {
                    if (cTotal == 100)
                    {
                        valid = true;
                    }
                    else
                    {
                       valid = false
                    }
                }
            }
            if (valid)
                return ValidationResult.Success;
            return new ValidationResult(result);
        }
    }

 

NB: Using MVVM pattern with SimpleMVVmToolkit.

Coordinator
Apr 27, 2012 at 5:43 AM

hi, what validation do you mean? SharpSerializer supports no validation attributes and I see no correlation between serialization and validation. After the object is deserialized it lives its own life further. apart from you example differs from the below one, have you shortend your example? where are items and cTotal stored?

msdn example:

http://msdn.microsoft.com/en-us/library/dd730022%28v=vs.95%29.aspx

Apr 27, 2012 at 8:38 AM

Hi Polo,

My apologies for not posting it earlier. You are right. There is no connection between your tool and validation. It was just my code that was updated that caused the error. All is good now and is working perfectly.

Thanks again.