locked
Why does the VB Data Annotation not accept a reference to my resource file error message? RRS feed

  • Question

  • User-404502133 posted

    Hi,

    VS2013, VB, working with MVC 5

    In this Code Project article which uses C# (link to article) the author shows a Data Annotation as below:  (about halfway down the linked page in a yellow code section)

    [Required(ErrorMessage=MyResources.Resources.NameRequiredError)]

    I thought the equivalent VB would be:

    <Required(ErrorMessage:=MvcMusicStore.Resources.ErrorMessages.FirstNameRequired)>

    My naming is slightly different:  The name of my error string is FirstNameRequired instead of the author's NameRequiredError.  My resource file is "ErrorMessages.resx" where the author's is named "resources.resx".  Unfortunately the author's resource file is named the same as the keyword "Resources" that is in my project's Intellisense.  Although these names are different, as I type each term in the line above, everything shows up just fine in Intellisense so I'm assuming my references are being setup correctly.

    But Visual Studio complains about the assignment above saying:

    Constant expression is required

    I was successful using that same error message from the default resource file named "ErrorMessages.resx" with the following line:

    <Required(ErrorMessageResourceName:="FirstNameRequired", ErrorMessageResourceType:=GetType(Resources.ErrorMessages))>

    In the Code Project article I've referenced, about a screen scroll above the line I showed at the top of this post, there is a Solutions Explorer screen shot with a Class library where the author's .resx files are being kept.  I don't have that because the Visual Studio web site instructs to create the .resx files in a folder called App_GlobalResource (link).

    So my question is why can't I reference the elements of my resource file in a similar way to the Code Project article without the error message?

    Thanks.

    Best Regards,

    Alan

     

     

     

     

    Tuesday, September 9, 2014 12:55 PM

All replies