dotnet/roslyn

compilation error for multiple top-level statements

Open

#83691 opened on May 12, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-CompilersConcept-Diagnostic ClarityFeature - Simple Programshelp wanted

Description

Is your feature request related to a problem? Please describe.

on dotnet build I was getting error CS8802

dotnet build

Restore complete (2.4s)

  Hms net10.0 failed with 1 error(s) (0.9s)

    T:\TempVS\HIS2026\Backend\Hms\Program.cs(21,1): error CS8802: Only one compilation unit can have top-level statements.



Build failed with 1 error(s) in 4.1s

Describe the solution you'd like

in case of this error the Error message should list all the 'top-level' ( 'entry point') statements with file name, so the fix will be quite easy.

Additional context

  • In my case issue was (ps. {}) in some other file but see the error message it is confusing
using System;using System.Collections.Generic;using System.Text;using Hms.Modules.Common.Entities;using Hms.Modules.Auth.Entities;

{ }
namespace Hms.Modules.Auth.Entities

{

public class User : BaseEntity

{

public long userId { get; set; }

public string username { get; set; } = string.Empty;

public string passwordHash { get; set; } = string.Empty;

public bool isActive { get; set; }

public ICollection<UserRole> userRoles { get; set; } = new List<UserRole>();

}
}

Contributor guide