JsonPacketSerializer: EntityMovedEvent serialize throws NotSupportedException (JsonElement leak) #795

Closed
opened 2026-07-22 08:25:38 +00:00 by spikerj · 1 comment
Owner

Summary

JsonPacketSerializer.SerializeEvents throws NotSupportedException when given an EntityMovedEvent under AoT/source-generated STJ.

Root cause

In SerializeEventToDict, the EntityMovedEvent arm is the only case that does:

dict = JsonSerializer.Deserialize<Dictionary<string, object?>>(json1, GameServerJsonContext.Default.DictionaryStringObject) ?? dict;

leaving JsonElement values in the dictionary. Every other event arm uses ConvertJsonToDictionary, which unwraps to primitives.

When SerializeEvents then writes List<Dictionary<string, object?>> via GameServerJsonContext, AoT rejects JsonElement.

Repro

Pinned characterization test: JsonPacketSerializerSwitchCoverageTests.SerializeEvents_EntityMovedEvent_ThrowsNotSupported_DueToJsonElementLeak on branch test/coverage-wave-2026-07 / PR #454.

Fix

Change the EntityMovedEvent arm to use ConvertJsonToDictionary(json1) like the sibling cases.

Impact

JSON (browser/debug) clients cannot receive entity-moved events; MessagePack path is unaffected.

## Summary `JsonPacketSerializer.SerializeEvents` throws `NotSupportedException` when given an `EntityMovedEvent` under AoT/source-generated STJ. ## Root cause In `SerializeEventToDict`, the `EntityMovedEvent` arm is the only case that does: ```csharp dict = JsonSerializer.Deserialize<Dictionary<string, object?>>(json1, GameServerJsonContext.Default.DictionaryStringObject) ?? dict; ``` leaving `JsonElement` values in the dictionary. Every other event arm uses `ConvertJsonToDictionary`, which unwraps to primitives. When `SerializeEvents` then writes `List<Dictionary<string, object?>>` via `GameServerJsonContext`, AoT rejects `JsonElement`. ## Repro Pinned characterization test: `JsonPacketSerializerSwitchCoverageTests.SerializeEvents_EntityMovedEvent_ThrowsNotSupported_DueToJsonElementLeak` on branch `test/coverage-wave-2026-07` / PR #454. ## Fix Change the `EntityMovedEvent` arm to use `ConvertJsonToDictionary(json1)` like the sibling cases. ## Impact JSON (browser/debug) clients cannot receive entity-moved events; MessagePack path is unaffected.
Author
Owner

Migrated to spikerj/spikersoft-backend#541 as part of the umbrella-tracker breakup.

Verified 2026-08-07 against the synced default branch.

  • Code: spikersoft-backend@98102023 — still broken. SpikerSoft.GameServer/Network/JsonPacketSerializer.cs:170 is still the lone arm that does JsonSerializer.Deserialize<Dictionary<string, object?>>(json1, GameServerJsonContext.Default.DictionaryStringObject), leaving JsonElement values in the dictionary that :90 then hands to ListDictionaryStringObject under AoT.
  • Live: docker service ps spikersoft-gameserver_spikersoft-gameserver → 1/1 Running on SERVER, image redeployed 2026-08-07 12:25 UTC; JSON (browser/debug) clients still cannot receive entity-moved events. MessagePack path unaffected.
  • Remaining: Change the EntityMovedEvent arm at :170 to use ConvertJsonToDictionary(json1) like the sibling cases, then flip JsonPacketSerializerSwitchCoverageTests.SerializeEvents_EntityMovedEvent_ThrowsNotSupported_DueToJsonElementLeak.

Status: still broken — full detail carried over to the new issue.

Closing here. Work now lives in the repo that holds the fix, so fixes #541 in a PR will
auto-close it on merge. The umbrella tracker keeps cross-repo epics only.

— Opus 5 Agent

Migrated to **spikerj/spikersoft-backend#541** as part of the umbrella-tracker breakup. Verified 2026-08-07 against the synced default branch. - **Code:** `spikersoft-backend@98102023` — still broken. `SpikerSoft.GameServer/Network/JsonPacketSerializer.cs:170` is still the lone arm that does `JsonSerializer.Deserialize<Dictionary<string, object?>>(json1, GameServerJsonContext.Default.DictionaryStringObject)`, leaving `JsonElement` values in the dictionary that `:90` then hands to `ListDictionaryStringObject` under AoT. - **Live:** `docker service ps spikersoft-gameserver_spikersoft-gameserver` → 1/1 Running on SERVER, image redeployed 2026-08-07 12:25 UTC; JSON (browser/debug) clients still cannot receive entity-moved events. MessagePack path unaffected. - **Remaining:** Change the `EntityMovedEvent` arm at `:170` to use `ConvertJsonToDictionary(json1)` like the sibling cases, then flip `JsonPacketSerializerSwitchCoverageTests.SerializeEvents_EntityMovedEvent_ThrowsNotSupported_DueToJsonElementLeak`. Status: still broken — full detail carried over to the new issue. Closing here. Work now lives in the repo that holds the fix, so `fixes #541` in a PR will auto-close it on merge. The umbrella tracker keeps cross-repo epics only. — Opus 5 Agent
Sign in to join this conversation.