"Assembly.cs global usings as project bootstrap"
▸ SYMPTOM
- C# can't find your Razor panels (
Hudnot found). - Every file needs the same
using Sandbox;/using System.Linq;boilerplate or won't compile. - Razor resolves Sandbox built-ins over your types.
▸ CAUSE
Code/Assembly.cs is the assembly-wide global usings file. Razor classes do not land in the global namespace: they need @namespace YourGame and global using YourGame; here, or the rest of the project can't see them (razor-namespace-trap).
▸ FIX
global using Sandbox;
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Threading.Tasks;
global using YourGame; // MUST match @namespace in every .razorIn every .razor:
@namespace YourGame
@inherits PanelComponentcsproj notes: TargetFramework net10.0, Razor via Microsoft.NET.Sdk.Razor, references Steam s&box managed DLLs. Verify with:
dotnet build Code\<project>.csprojDon't name classes after Sandbox built-ins. A global-namespace PlayerController compiles, but Razor resolves Sandbox.PlayerController first and you get baffling "no such member" errors. This also applies to UI components: naming a PanelComponent something like LoadingScreen hits CS0104: ambiguous reference because Sandbox.LoadingScreen is a real built-in type. Check the name against the Sandbox API before creating player/camera/inventory/HUD-ish classes. Prefix project-specific names (e.g. MyLoadingScreen) rather than using generic names that Sandbox has already taken.
This extends to member names too. Naming a UI panel member OnBack collides with the engine's built-in Sandbox.UI.Panel.OnBack(PanelEvent) virtual hook: a public Action OnBack property trips CS0108 (member shadowing) instead of the ambiguous-reference error above. It's the same family of collision, just at the member level rather than the type level. Fix: rename (e.g. BackRequested). General rule: Panel exposes many virtual event hooks (OnBack, OnBlur, etc.). Check the base type before naming a public member On*.
▸ WHY IT WORKS
Global usings apply to every compilation unit in the game assembly. Matching global using to Razor's @namespace puts generated panel types in the same scope as your components, which is the whole point of a single Assembly.cs bootstrap file.