'ErrorMessageResourceType' property specified was not found. on XmlSerialise
- by Redeemed1
In my ASP.Net MVC app I have a Model layer which uses localised validation annotations on business objects.
The code looks like this:
[XmlRoot("Item")]
public class ItemBo : BusinessObjectBase
{
[Required(ErrorMessageResourceName = "RequiredField", ErrorMessageResourceType = typeof(StringResource))]
[HelpPrompt("ItemNumber")]
public long ItemNumber { get; set; }
This works well.
When I want to serialise the object to xml I get the error:
"'ErrorMessageResourceType' property specified was not found" (although it is lost beneath other errors, it is the innerexception I am trying to work on.
The problem therefore is the use of the DataAnnotations attributes. The relevant resource files are in another assembly and are marked as 'public' and as I said everything works well until I get to serialisation.
I have references to the relevant DataAnnotations class etc in my nunit tests and target class.
By the way, the HelpPrompt is another data annotation I have defined elsewhere and is not causing the problem.
Furthermore if I change the Required attribute to the standard format as follows, the serialisation works ok.
[Required(ErrorMessage="Error")]
Can anyone help me?