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

Open
opened 2026-07-22 08:25:38 +00:00 by spikerj · 0 comments
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.
Sign in to join this conversation.