title: DisplayAttribute: No good for resources in App_GlobalResources
body: <p>This question applies to all projects really, however my demonstrating environment is an MVC3 app, hence that tag.</p>
  
  <p>I wrote a <code>DisplayNameAttribute</code>-derived class for our MVC2 projects, like so many people have, so I could localise display names in MVC editors and display templates.  I lifted the <code>ValidationAttribute</code> localisation code used for the error message so that it behaved in a 'standard' way.</p>
  
  <p>Then I noticed that in MVC3 we have the <code>DisplayAttribute</code>, so I dutifully obsoleted my attribute class in the .Net 4 version of my MVC extension framework and changed the model properties in my current project to use this, e.g:</p>
  
  <pre><code>[Display(ResourceType = typeof(Resources.MyResources), Name = "ResourceName")]
  public string ModelProperty { get; set; }
  </code></pre>
  
  <p>Then I run the web app and I get an error similar to this:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: Cannot retrieve property 'Name' because localization failed.  Type '[Resource Type Here]' is not public or does not contain a public static string property with the name '[Resource Name Here]'.</p>
  </blockquote>
  
  <p>I use localisation in various places of course, and in class libraries such resources will be typically be marked public.  In web applications, however, I will use the <code>App_GlobalResources</code> folder because, well, <em>that's what it's for!</em></p>
  
  <p>The problem here is that the resource accessors that are generated for resx files in this folder are <strong>always</strong> generated as internal access, with no way of changing it.</p>
  
  <p>So, since <code>DisplayAttribute</code> seems only to look for public members (whereas the localisation code I copied from <code>ValidationAttribute</code> and applied to my own <code>DisplayNameAttribute</code>-deriving type simply looks for static members with either public OR internal visibility), it would appear that <code>DisplayAttribute</code> is off-limits to any MVC web apps that intend to use <code>App_GlobalResources</code> for the localised strings?</p>
  
  <p>Apart from the fact that this is <em>probably</em> a bug in <code>DisplayAttribute</code>, has anybody else hit this problem?  What did you do to solve it?  Should I honour the usage of <code>DisplayAttribute</code> and change all my resources to be 'properly' embedded as in the class library projects, and set them all as public?  Or should I ditch DisplayAttribute in favour of my other class that I know works!?</p>