C#idiomatic C#
ide0130fundamentals/code-analysis/style-rules

Code analysis

Namespace does not match folder structure (IDE0130)

Learn about code analysis rule IDE0130: Namespace does not match folder structure

IDE0130 Style / Language rules (expression-level preferences)
Applicable languages C# and Visual BasicOptions dotnet_style_namespace_match_folder

Overview

This style rule uses the folder structure of the project to enforce namespace naming requirements.

Options

Options specify the behavior that you want the rule to enforce. For information about configuring options, see Option format.

dotnet_style_namespace_match_folder

Property Value Description
Option name dotnet_style_namespace_match_folder
Option values true Prefer namespace naming to match folder structure.
false Disables the rule.
Default option value true

Example

Assume that the following code snippets are from a file named Data/Example.cs or Data/Example.vb, where Data represents the folder structure from the project file. The folder structure naming is added to the root namespace, which in this example is Root.

csharp
// Code with violations
namespace Root.BadExample
{
    class Example
    {
        public void M()
        {
        }
    }
}

// Fixed code
namespace Root.Data
{
    class Example
    {
        public void M()
        {
        }
    }
}
vb
' Code with violations
Namespace Root.BadExample
    Class Example
        Public Sub M()
        End Sub
    End Class
End Namespace

' Fixed code
Namespace Root.Data
    Class Example
        Public Sub M()
        End Sub
    End Class
End Namespace

Suppress a warning

If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

csharp
#pragma warning disable IDE0130
// The code that's violating the rule is on this line.
#pragma warning restore IDE0130

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

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

To disable all of the code-style rules, set the severity for the category Style to none in the configuration file.

ini
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none

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

See also