Original message (verbatim)
CS0116: A namespace cannot directly contain members such as fields, methods or statements.
Placeholders such as %s / %d are kept verbatim from the engine source and are not replaced with concrete values.
Trigger
A class, struct, or method is written at the namespace level (missing class wrapper, mismatched braces, or a method body written at the top level of the script), and compilation reports CS0116.
Typical cause
A namespace can only contain type declarations; fields, methods, and statements must live inside a class or struct, so the compiler flags any top-level member.
Step-by-step fix
- Wrap fields and methods inside a class or struct declaration.
- Check brace matching so the namespace level contains only types.
- Confirm the class declaration line was not accidentally removed.
Source links
Per-entry sources and capture date are listed at /sources#U27.
Related errors
Related Unity errors
Need an offline quick-reference checklist?
Atlas error library Pro pack: 123 error references (110 single + 13 merged) plus a quick-fix guide, $19 one-time purchase, delivered as electronic files.
Back to the all-errors index Checkout and buy the Pro pack — $19.00