CA1824: Mark assemblies with NeutralResourcesLanguageAttribute
Property | Value |
---|---|
Rule ID | CA1824 |
Title | Mark assemblies with NeutralResourcesLanguageAttribute |
Category | Performance |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 9 | As suggestion |
Cause
An assembly contains a ResX-based resource but does not have the System.Resources.NeutralResourcesLanguageAttribute applied to it.
Rule description
The NeutralResourcesLanguageAttribute attribute informs the resource manager of an app's default culture. If the default culture's resources are embedded in the app's main assembly, and ResourceManager has to retrieve resources that belong to the same culture as the default culture, the ResourceManager automatically uses the resources located in the main assembly instead of searching for a satellite assembly. This bypasses the usual assembly probe, improves lookup performance for the first resource you load, and can reduce your working set.
Tip
See Package and deploy resources for the process that ResourceManager uses to probe for resource files.
Fix violations
To fix a violation of this rule, add the attribute to the assembly, and specify the language of the resources of the neutral culture.
To specify the neutral language for resources
In Solution Explorer, right-click your project, and then select Properties.
Select the Package tab.
Note
If your project is a .NET Framework project, select the Application tab, and then select Assembly Information.
Select the language from the Neutral language or Assembly neutral language drop-down list.
Select OK.
When to suppress warnings
It's permissible to suppress a warning from this rule. However, startup performance might degrade. To suppress this warning, add dotnet_diagnostic.CA1824.severity = none
to your .globalconfig or .editorconfig file.
Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA1824
// The code that's violating the rule is on this line.
#pragma warning restore CA1824
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA1824.severity = none
For more information, see How to suppress code analysis warnings.