Skip to content

SA1649 and SA1402 - Doesn't work when using C# 10 File-scoped Namespaces #3435

@hannahchan

Description

@hannahchan

I'm using StyleCop.Analyzers version, 1.2.0-beta.376.

When given a file named Example.cs with the following content using file-scoped namespaces in C# 10:

namespace MyExample;

public class TestClass1
{
}

public class TestClass2
{
}

The rules SA1649 - File name should match first type name and SA1402 File may only contain a single type stop working. When switching back to block-scoped namespaces, the rules start working again. The following code triggers the rules correctly.

namespace MyExample
{
    public class TestClass1
    {
    }

    public class TestClass2
    {
    }
}

There may be other rules that don't work when using file-scoped namespaces in C# 10. I've only discovered these two.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions