tag

#csharp

10 items (10 fixes)

fixes
26.07.22
"A code-behind Panel has no Style.Rotate shortcut: rotate it with a PanelTransform"

A pure C# Panel subclass has no settable Style.Rotate shortcut reachable from code the way razor markup can write transform:rotate(Xdeg). Rotate it by building a PanelTransform, calling AddRotation, and assigning it to Style.Transform each frame the angle changes.

26.07.22
"A property initializer that reads another property compiles headless but breaks the editor (CS0182)"

public int X { get; init; } = SomeClass.SomeProperty; passes headless dotnet build but fails the editor compile with CS0182: the editor's code generator embeds initializers where only constants are legal. Default to a constant sentinel and resolve later.

26.07.22
"A struct's Default => new() silently skips your all-optional constructor"

public static Config Default => new(); on a struct binds to the runtime's implicit parameterless constructor, not your declared all-optional-parameter constructor: every intended default is silently discarded and the value comes back default(T).

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

A single-line XML doc comment that shares a line with the field it documents pulls the declaration into the comment. The compiler then sees no field at all. Nothing fails at the comment site. The break shows up later as a 'does not contain a definition' error wherever the field is used, which reads like a typo or a missing using. Put every XML doc comment on its own line, directly above the member.

26.07.08e
"Array.Clone() blocked by whitelist but dotnet build misses it"

System.Array.Clone() compiles clean in dotnet build but fails SB1000 in the editor: the headless build does not enforce the whitelist.

26.07.15a
"Assembly.cs global usings as project bootstrap"

global using Sandbox + your razor namespace in Assembly.cs: without it, panels and game types don't resolve across the assembly.

26.07.15a
"Cross-assembly hot-reload throws MissingMethodException despite green compile"

Adding a public method to the game assembly and calling it from the editor-tools assembly in the same hot-reload pass throws MissingMethodException at runtime: both compile_status and dotnet build are green.

26.07.08e
"Naming a property 'Active' shadows Component.Active"

Component.Active is a real inherited member: naming your own bool Active silently shadows the engine's enabled flag. It is a CS0108 warning, not an error, so it ships easily; treat CS0108 as an error in code review.

26.07.08e
"Scaffolded project missing global using System in Assembly.cs"

A freshly-scaffolded project's Assembly.cs can be missing global using System. Transplanted code using Math/MathF fails with CS0103.

26.07.15a
"TextEntry.OnTextEdited needs an explicit-type block lambda"

An untyped or expression-bodied lambda on TextEntry.OnTextEdited fails with CS8917 or CS0029. Use an explicit param type plus a block body.

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