Invalid token 'token' in class, struct, or interface member declaration

This error occurs when code contains content that doesn't belong or is missing, causing the next content to read as unexpected.



Ensure your IDE is configured, the area should be underlined in red. Don't proceed without it functioning.

  1. Understand stack traces to pinpoint the problematic lines. The line mentioned, or the one before it can use this compiler error.
  2. The previous statement must end in a semi-colon (;) if it doesn't open a scope like a for or if.
  3. Look at examples of similar code and pay close attention to missing, additional, or misspelt characters. Misplaced semi-colons (;) are most likely to cause this error.
  4. Logic, keywords, or symbols in the line of code may be invalid where they are written.
    1. Don't write variable declarations outside of a type.
    2. Don't write logic outside of a method or property.
    3. Don't use access modifiers (public for example) with local variables.
    4. Don't use accessors (. for example) in variable declarations.
  5. All statements must be complete, partially-written lines of code are invalid.

Examples of extra or missing characters:#

Examples of partially-written lines of code:#