the symptom, in your words

"An XML doc comment on the field's own line deletes the field"

✓ verified on 26.07.22
lane Building UIposted

▸ SYMPTOM

  • A field you declared does not exist as far as the compiler is concerned.
  • The error does not point at the field. It fires downstream, wherever the field is read, as 'Foo' does not contain a definition for 'MinX'.
  • The message reads like a typo or a missing using, so you look everywhere except the declaration line.

▸ CAUSE

The field and its XML doc comment share one line:

snippet
/// <summary>Minimum X.</summary> public float MinX;

A /// triple-slash sequence starts a comment that runs to the end of the line. Everything after it on that line is comment text. So public float MinX; is inside the comment, and the compiler parses one doc-comment line and no member.

There is no syntax error at the declaration, because a doc comment followed by nothing is legal. The type simply has no MinX. The first real error appears at the first use of MinX, one or more files away from the cause.

▸ FIX

Put the XML doc comment on its own line, directly above the member it documents:

snippet
/// <summary>Minimum X.</summary>
public float MinX;

The comment now ends before the declaration starts, so the compiler reads both. When a does not contain a definition error names a member you are sure you declared, open the declaration and check whether a /// comment sits on the same line.

▸ WHY IT WORKS

A /// comment ends at the newline, not at the end of the tag. On a shared line the declaration falls inside the comment span and never reaches the parser. Moving the comment to its own line puts the newline between the comment and the field, so the field parses as a member.

Verified on engine 26.07.22: seen in a real project.
s&box moves fast; an undated fix is a liability. Spot a stale detail?
changelog
  • Published

Want to know when new guides or fixes drop? Join the community to help build this out. Report gotchas, flag outdated fixes, or just lurk.

Join the Discord