Get ErrorMessage from ResourceFile / RIA Services
My goal is simply to show a language-specific errormessage for a Required-Annotation:
[Required(ErrorMessageResourceName = "LastNameRequired", ErrorMessageResourceType = typeof(ValidationMessage))]
LastNameRequired is the key of the string in the resourcefile, ValidationMessage is the type generated by the resource file. The resourcefile is in the same project and namespace.
I changed the Access Modifier of the resourcefile to public. Build Action is on Embedded Resource.
The actual behaviour is, that it doesn't show an errormessage, it even doesn't show an error for that attribute. If I remove the Erro开发者_如何学JAVArMessage*-Attribute from the Attribute, all works fine.
[Required]
When you use a generated resource class, check if it has public properties. Resources has only internal properties as default, so you must select the Resource file (.resx) in Solution Explorer and in window Properties replace Custom Tool field value "ResXFileCodeGenerator" with "PublicResXFileCodeGenerator" then rebuild solution...
I found the solution. The problem occured, because I didn't used the default-namespaces. I had to add a -element in the project file for the linked resources.
精彩评论