C#idiomatic C#
ca1824fundamentals/code-analysis/quality-rules

Code analysis

CA1824: Mark assemblies with NeutralResourcesLanguageAttribute

Learn about code analysis rule CA1824: Mark assemblies with NeutralResourcesLanguageAttribute

CA1824 Performance enabled by default in .NET 10: As suggestion
Fix is breaking or non-breaking Non-breakingApplicable languages C# and Visual Basic

Cause

An assembly contains a ResX-based resource but does not have the System.Resources.NeutralResourcesLanguageAttribute applied to it.

Rule description

The System.Resources.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 System.Resources.ResourceManager has to retrieve resources that belong to the same culture as the default culture, the System.Resources.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.

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

  1. In Solution Explorer, right-click your project, and then select Properties.

  2. Select the Package tab.

  3. Select the language from the Neutral language or Assembly neutral language drop-down list.

  4. 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.

csharp
#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.

ini
[*.{cs,vb}]
dotnet_diagnostic.CA1824.severity = none

For more information, see How to suppress code analysis warnings.

See also