{"record":{"id":"2ee95f6c86dcd25e","repo":"JeffreySu/WeiXinMPSDK","slug":"json-typeof-t-fullname","errorCode":null,"errorMessage":"JSON 反序列化结果为空，目标类型：{typeof(T).FullName}","messagePattern":"JSON 反序列化结果为空，目标类型：(.+?)","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin/Senparc.Weixin/Helpers/Serializers/WeixinJsonSerializer.cs","lineNumber":92,"sourceCode":"        /// <summary>\n        /// 使用调用方提供的源生成元数据反序列化对象。\n        /// </summary>\n        public static T Deserialize<T>(string json, JsonTypeInfo<T> jsonTypeInfo)\n        {\n            if (json == null)\n            {\n                throw new ArgumentNullException(nameof(json));\n            }\n\n            if (jsonTypeInfo == null)\n            {\n                throw new ArgumentNullException(nameof(jsonTypeInfo));\n            }\n\n            var result = JsonSerializer.Deserialize(json, jsonTypeInfo);\n            if (result == null)\n            {\n                throw new WeixinException($\"JSON 反序列化结果为空，目标类型：{typeof(T).FullName}\");\n            }\n\n            return result;\n        }\n\n        /// <summary>\n        /// 使用 SDK 内置源生成元数据反序列化微信错误结果。\n        /// </summary>\n        public static WxJsonResult DeserializeWxJsonResult(string json)\n        {\n            return Deserialize(json, WeixinJsonSerializerContext.Default.WxJsonResult);\n        }\n    }\n}\n","sourceCodeStart":74,"sourceCodeEnd":107,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin/Senparc.Weixin/Helpers/Serializers/WeixinJsonSerializer.cs#L74-L107","documentation":"WeixinJsonSerializer.Deserialize<T> uses System.Text.Json's JsonSerializer.Deserialize with JsonTypeInfo, and throws WeixinException when the JSON input deserializes to null even though a T instance was expected. This guards callers from silently receiving a null object for a non-nullable T. It typically means the response body was 'null' (literally) or an empty/invalid payload.","triggerScenarios":"Calling Deserialize<T> (or DeserializeWxJsonResult) on a JSON string that is 'null', whitespace, or a payload System.Text.Json maps to null for the given JsonTypeInfo.","commonSituations":"WeChat API returned an empty body or literal 'null' due to an upstream error; passing an empty response body from HttpClient; mismatched T/JsonTypeInfo where the JSON shape does not produce a value.","solutions":["Check the raw JSON string is non-empty and not 'null' before deserializing; inspect the HTTP response body and status.","Log the raw payload and target type to identify why deserialization yields null.","Verify the correct JsonTypeInfo/context is used for T so the payload maps to a real object.","Catch WeixinException and treat it as an upstream/API error with the raw body preserved for debugging."],"exampleFix":"// before\nvar result = WeixinJsonSerializer.Deserialize<WxApiResult>(body, jsonTypeInfo);\n// after\nif (string.IsNullOrWhiteSpace(body) || body.Trim() == \"null\")\n    throw new WeixinException($\"Empty/null response body: {body}\");\nvar result = WeixinJsonSerializer.Deserialize<WxApiResult>(body, jsonTypeInfo);","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(json) || json.Trim() == \"null\")\n    throw new WeixinException(\"Response body is empty or null\");","typeGuard":"static bool IsDeserializable(string json) =>\n    !string.IsNullOrWhiteSpace(json) && json.Trim() != \"null\";","tryCatchPattern":"try { result = WeixinJsonSerializer.Deserialize<T>(json, jsonTypeInfo); }\ncatch (WeixinException ex) { logger.LogError(ex, \"Null deserialization for {T}: {Body}\", typeof(T).Name, json); }","preventionTips":["Always inspect raw HTTP body and status before deserializing","Log the payload alongside the target type","Use the matching JsonSerializerContext/JsonTypeInfo for T"],"tags":["csharp","json","serialization","weixin"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}