csharp_style_namespace_declarations causes compilation errors with #region directives
- Dominant language
- No language data
- Stars
- 1.9k
- Forks
- 173
- Avg merge
- 10d 13h
- Merged PRs (30d)
- 1
Description
## Summary
When `csharp_style_namespace_declarations` is fixed in code that contains `#region` blocks, the `#endregion` can be lost, causing compilation errors. It only happens when running `dotnet format`, not when applying the namespace declaration code fix from Visual Studio.
## Reproduction Steps
Given the following `.editorconfig` file:
```ini
[*.cs]
csharp_style_namespace_declarations = file_scoped:warning
```
And the following Program.cs with a `#region`:
```csharp
namespace MyNamespace
{
#region SuperCoolCode
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
#endregion
}
```
Running `dotnet format` will result in the following code that fails to compile (`CS1038 #endregion directive expected`):
```csharp
namespace MyNamespace;
#region SuperCoolCode
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
```
Applying the code fix from within Visual Studio (17.1.0 Preview 4.0) works correctly without an error:

## Version Info
`dotnet format --version` returns `6.0.252703+68bc36719088c86b0ff01334039b0611741b8276`
`dotnet --info` returns:
```
.NET SDK (reflecting any global.json):
Version: 6.0.200-preview.22055.15
Commit: a3c3a2bf3b
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.200-preview.22055.15\
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.