{"record":{"id":"ca49381c20b7a0bd","repo":"microsoft/semantic-kernel","slug":"failed-to-serialize-enum-name","errorCode":null,"errorMessage":"Failed to serialize Enum Name","messagePattern":"Failed to serialize Enum Name","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Experimental/Process.Core/WorkflowSerializer.cs","lineNumber":222,"sourceCode":"            }\n\n            return this._baseConverter.CreateConverter(typeToConvert, options);\n        }\n    }\n\n    internal class JsonNamingPolicyDecorator : JsonNamingPolicy\n    {\n        private readonly JsonNamingPolicy? _underlyingNamingPolicy;\n\n        public JsonNamingPolicyDecorator(JsonNamingPolicy? underlyingNamingPolicy) => this._underlyingNamingPolicy = underlyingNamingPolicy;\n        public override string ConvertName(string name) => this._underlyingNamingPolicy?.ConvertName(name) ?? name;\n    }\n\n    internal class DictionaryLookupNamingPolicy : JsonNamingPolicyDecorator\n    {\n        private readonly Dictionary<string, string> _dictionary;\n\n        public DictionaryLookupNamingPolicy(Dictionary<string, string> dictionary, JsonNamingPolicy? underlyingNamingPolicy) : base(underlyingNamingPolicy) => this._dictionary = dictionary ?? throw new KernelException(\"Failed to serialize Enum Name\");\n        public override string ConvertName(string name) => this._dictionary.TryGetValue(name, out var value) ? value : base.ConvertName(name);\n    }\n}\n","sourceCodeStart":204,"sourceCodeEnd":226,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Experimental/Process.Core/WorkflowSerializer.cs#L204-L226","documentation":"Thrown by the internal `DictionaryLookupNamingPolicy` constructor when the `dictionary` argument passed to it is null. This naming policy maps enum names to serialized strings during JSON serialization; a null lookup table is a programmer error in the serializer setup, not a user-data problem. It is a KernelException.","triggerScenarios":"The enum-name query that feeds `DictionaryLookupNamingPolicy` produces a null dictionary (e.g. an extension method returning null) and that null is passed into the constructor; custom code instantiates this internal class with a null dictionary.","commonSituations":"Internal serializer bug or reflection-based query returning null unexpectedly; custom serialization pipeline wiring that bypasses the null-coalescing guard upstream; this is rarely hit by end users since the class is internal.","solutions":["Report/fix the upstream code that produces a null enum-name dictionary (the query at the call site should yield an empty dict, not null).","Ensure any custom use passes a non-null dictionary, defaulting to `new()` when empty.","Upgrade the Process.Core package in case the null-source bug is already patched."],"exampleFix":"// before\nreturn new DictionaryLookupNamingPolicy(null, this._namingPolicy);\n// after\nreturn new DictionaryLookupNamingPolicy(query ?? new Dictionary<string,string>(), this._namingPolicy);","handlingStrategy":"validation","validationCode":"// If you invoke internal serializer plumbing, never pass null.\nvar lookup = query?.ToDictionary(p => p.Item1, p => p.Item2) ?? new Dictionary<string, string>();\nvar policy = new DictionaryLookupNamingPolicy(lookup, namingPolicy);","typeGuard":"bool IsNonNullDictionary(Dictionary<string,string> d) => d is not null;","tryCatchPattern":"try { serializer.Serialize(obj); }\ncatch (KernelException ex) when (ex.Message.Contains(\"Failed to serialize Enum Name\"))\n{ _logger.LogError(ex, \"Enum-name lookup dictionary was null; serializer misconfigured.\"); throw; }","preventionTips":["Ensure enum-name query methods return an empty dictionary rather than null.","Treat this as a library bug to report upstream if hit without custom serializer code."],"tags":["workflow","process-framework","serialization","json","internal"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}