What does the NeutralResourcesLanguageAttribute do?

NeutralResourcesLanguageAttribute marks the neutral culture for an assembly. That sounds self-referential, but a full description would require another blog post. To avoid getting bogged down, think of neutral culture roughly as the default language. (Fingers crossed that Michael Kaplan doesn’t flame me for that oversimplification.)

The NeutralResourcesLanguageAttribute does two things:

1. Can speed up resource probes.

First note that the default location for neutral resources is the main assembly. In other words:
…is the same as:
[assembly:NeutralResourcesLanguageAttribute(“en-US”, UltimateResourceFallbackLocation.MainAssembly)]

If you have one of the above attributes on your assembly, then the ResourceManager looks for “en-US” resources directly in the main assembly, instead of searching first in an “en-US” folder. Since resource probes can be expensive, this attribute can help improve perf.

2. Specifies a fallback culture if resource probes fail; i.e. neutral resources are the resources that should always be there.

Suppose you want to deploy an app on a machine typically set to de-DE culture. Suppose you have partially localized strings for de-DE and de, and a full set of resources for fr-FR. You can use NeutralResourcesLanguageAttribute to say fr-FR resources are always there. So if the resource probe doesn’t find an entry for de-DE or de, then it will fallback to fr-FR.

You can use the accompanying attribute UltimateResourceFallbackLocation.Satellite to say these resources are located in a satellite assembly, i.e.:
[assembly:NeutralResourcesLanguageAttribute(“fr-FR”, UltimateResourceFallbackLocation.MainAssembly)]

Comments (5)

  1. David Kean says:

    We added a warning to FxCop that fires on assemblies that contain ResourceManager-managed resources, but do not have the NeutralResourcesLanguageAttribute specified.

    For more information, see: http://blogs.msdn.com/kimhamil/archive/2008/11/11/what-does-the-neutralresourceslanguageattribute-do.aspx

  2. MSDNArchive says:

    Thanks David, that’s good news! Can you re-post the link though? (It links to my post.)

  3. The essentials of resource fallback and how to debug failures Resource loading failures can be tricky

  4. Kim Hamilton says:

    In an earlier blog about resource fallback essentials , I said that the resource diagnostic tool resview