the symptom, in your words

"Assembly.cs global usings as project bootstrap"

✓ verified on 26.07.15a
lane Getting set upposted updated

▸ SYMPTOM

  • C# can't find your Razor panels (Hud not 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

snippet
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 .razor

In every .razor:

snippet
@namespace YourGame
@inherits PanelComponent

csproj notes: TargetFramework net10.0, Razor via Microsoft.NET.Sdk.Razor, references Steam s&box managed DLLs. Verify with:

snippet
dotnet build Code\<project>.csproj

Don'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.

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

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