'ErrorMessageResourceType' property specified was not found. on XmlSerialise

Posted by Redeemed1 on Stack Overflow See other posts from Stack Overflow or by Redeemed1
Published on 2010-06-10T16:49:39Z Indexed on 2010/06/10 16:52 UTC
Read the original article Hit count: 674

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about Xml