13

I have culture specific resource files in App_GlobalResources folder. Now I need to read value of the DisplayName attribute from this resource files. I am using:

[Display(Name = "MerchantName", ResourceType = typeof(Resource))]
public string Merchant { get; set; }

but I am getting the following error:

Cannot retrieve property 'Name' because localization failed. Type 'Resources.Resource' is not public or does not contain a public static string property with the name 'MerchantName'.

How do I solve this problem?

Achinth Gurkhi
  • 2,136
  • 4
  • 24
  • 45

2 Answers2

21

In my case I had to change the Access modifier of my resource from Internal to Public.

Public_vs_Internal

By default all Resources are created as Internal.

michal
  • 317
  • 2
  • 5
  • This worked for me too. I saw the 'internal' in the code, but didn't know where to change it. I was about to waste a lot of time. Thanks. – elcool Jul 22 '15 at 15:56
  • It's works. before it, I change modifier of resource manually. – A.Dara Jan 25 '17 at 12:41
  • In my case (ASP.Net MVC VS 2019), the access modifier dropdown was disabled. This https://stackoverflow.com/a/36790016/199745 fixed the disabled dropdown issue.After the dropdown was enabled, the access modifier was automatically set to public. – Moiz Tankiwala Oct 09 '19 at 06:00
0

Check the following:

  1. Your resource file access modifier should be declared as public;

  2. It contains a key MerchantName

    [Display(ResourceType = typeof(Resource), Name = "MerchantName")]
    public string MerchantName{ get; set; }
    

For more information, refer http://www.dotnetlibrary.com/Articles/GetArticles?articleId=20

Prabhat
  • 65
  • 4