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:
[assembly:NeutralResourcesLanguageAttribute("en-US")]
...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)]

Published 11 November 08 03:44 by kimhamil
Filed under:

Comments

# What does the NeutralResourcesLanguageAttribute do? | Tmao Coders said on November 11, 2008 7:11 PM:

PingBack from http://www.tmao.info/what-does-the-neutralresourceslanguageattribute-do/

# David Kean said on November 11, 2008 7:50 PM:

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

# kimhamil said on November 11, 2008 8:11 PM:

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

# BCL Team Blog said on February 16, 2009 4:30 PM:

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

# Kim Hamilton said on March 6, 2009 2:12 PM:

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

New Comments to this post are disabled

Search

This Blog

Syndication

Page view tracker