dotnet/roslyn

compilation error for multiple top-level statements

Fermée

#83 691 ouverte le 12 mai 2026

 (1 commentaire) (0 réaction) (0 personne assignée)C# (4 257 forks)batch import
Area-CompilersConcept-Diagnostic ClarityFeature - Simple Programshelp wanted

Métriques du dépôt

Stars
 (20 414 étoiles)
Métriques de merge PR
 (Merge moyen 6j 17h) (256 PRs mergées en 30 j)

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>();

}
}

Guide contributeur