Compiler error · error CS1022

Type or namespace definition, or end-of-file expected

That message is compiler-speak for: you have one closing brace too many. There's a } with no block left to close.

See it happen

int x = 5;
Console.WriteLine(x);
}   // ← nothing was opened for this brace to close

It's the mirror of CS1513

ErrorMeaningFix
CS1513 — } expectedToo few closing bracesAdd the missing }
CS1022Too many closing bracesDelete the extra }

Same diagnostic method, opposite direction. Count from the top of the file: { is +1, } is −1. If the count goes negative, you've just passed the extra brace.

The usual causes

1. Copy-paste brought an extra brace

class Greeter
{
    public void Hello()
    {
        Console.WriteLine("hi");
    }
}   // closes class
}   // ← pasted twice by accident

2. A block was deleted but its brace stayed

You removed an if or a method, and left its closing brace behind. The symptom is often a confusing cascade: everything after it appears to be outside the class.

3. Braces merged while reformatting

Auto-format can't fix broken brace counts — it can only align what's there. If two blocks merged, reindent visually and look for a line whose indentation doesn't match its neighbours.

How to fix it in 20 seconds

  1. Click the first { in the file; most editors highlight its partner.
  2. If a } highlights nothing, that brace has no opening partner — delete it.
  3. Or count +1/−1 from the top; the first place it dips negative is your extra brace.
  4. After deleting, run the auto-formatter — if the layout suddenly snaps into place, you found it.

This works in Visual Studio, VS Code and Rider. The engine here reports the same code the real compiler does, so you can practice the pattern above.

Frequently asked

What does CS1022 mean?

One more } than { — an extra closing brace. Count +1/−1 from the top; where the count goes negative is the brace to remove.

CS1022 vs CS1513?

CS1022 = too many closing braces; CS1513 = too few. Same counting method, opposite direction.

Checklist