Hotloading — live code reloading, IL fast path, and common pitfalls
Hotloading — Live Code Reloading
s&box recompiles and live-reloads your assembly whenever you save a .cs or .razor file. You don't need to restart the editor for most changes.
How It Works
IL Hotload (fast path) — if you only changed method bodies, s&box patches the instructions in-place. This is nearly instant and avoids all the pitfalls below. Enabled by default. Full Hotload — if you changed type definitions (added/removed fields, renamed types, changed signatures), s&box walks the heap to find and upgrade all existing instances of those types.Diagnosing Slow Hotloads
Run hotload_log 2 in the console to get a timing breakdown of which types are taking longest to process. If instance counts grow each hotload, you likely have a static list that's never cleared.
Pitfalls (Full Hotload Only)
Removing or Renaming Types
References to removed types become null. Renamed types are treated as removed — the old type disappears and the new one starts fresh. Restart the editor if you get cascading errors after a rename.
Changing Default Field Values
Runtime values are copied into the new assembly, so changing a field's default won't take effect until editor restart. Use a property with a => body or const to work around this:
// ❌ Won't update on hotload
public static string Name = "Old";
// ✔️ Always reflects the new value
public static string Name => "New";
public const string Name = "New";
// ✔️ Force skip — uses new default
[SkipHotload] public static string Name = "New";Static Fields in Generic Types
Static fields in generic types (MyClass<T>) are not processed during hotload — their values are lost. The compiler emits a warning for these. Suppress with [SkipHotload] if intentional.
Delegates and Lambdas
Hotload tries to preserve delegate instances but may fail if lambda methods are reordered or significantly changed. A failed delegate logs a warning when invoked.
Reflection Caches
If you cache reflection results, mark the cache field with [SkipHotload] and repopulate it after hotload to avoid stale data.
Dictionaries / HashSets
If a code change makes previously non-equal instances equal, dictionaries and sets can enter an invalid state. A warning is emitted and an editor restart may be needed.
Performance Tips
- Seal classes that don't need inheritance — hotload can skip them automatically
- Use struct arrays of value types — they have a fast path
- Avoid large static collections that grow unboundedly