{"record":{"id":"54c23a8685f8e17e","repo":"JeffreySu/WeiXinMPSDK","slug":"native-aot-h5-value-gettype-fullname-h5-info-ios-h5-info","errorCode":null,"errorMessage":"Native AOT 不支持未注册的 H5 场景类型：{value.GetType().FullName}。请使用 H5_Info_IOS、H5_Info_Android 或 H5_Info_WAP。","messagePattern":"Native AOT 不支持未注册的 H5 场景类型：(.+?)。请使用 H5_Info_IOS、H5_Info_Android 或 H5_Info_WAP。","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Entities/Request/TenPayJsonSerializer.cs","lineNumber":73,"sourceCode":"\n    internal static class TenPayJsonSerializer\n    {\n        internal static string Serialize<T>(T value)\n        {\n            var jsonTypeInfo = TenPayJsonSerializerContext.Default.GetTypeInfo(typeof(T));\n            if (jsonTypeInfo == null)\n            {\n                throw new NotSupportedException($\"未生成类型 {typeof(T).FullName} 的 JSON 元数据。\");\n            }\n\n            return JsonSerializer.Serialize(value, jsonTypeInfo);\n        }\n\n        internal static string SerializeCustomH5Info(IH5_Info value)\n        {\n            if (!JsonSerializer.IsReflectionEnabledByDefault)\n            {\n                throw new NotSupportedException(\n                    $\"Native AOT 不支持未注册的 H5 场景类型：{value.GetType().FullName}。\" +\n                    \"请使用 H5_Info_IOS、H5_Info_Android 或 H5_Info_WAP。\");\n            }\n\n#pragma warning disable IL2026\n#pragma warning disable IL3050\n            return JsonSerializer.Serialize(\n                new Dictionary<string, object> { [\"h5_info\"] = value },\n                new JsonSerializerOptions\n                {\n                    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull\n                });\n#pragma warning restore IL3050\n#pragma warning restore IL2026\n        }\n    }\n\n    internal sealed class StoreInfoJson","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Entities/Request/TenPayJsonSerializer.cs#L55-L91","documentation":"SerializeCustomH5Info can only serialize the pre-registered H5 scene types (H5_Info_IOS, H5_Info_Android, H5_Info_WAP) via source-generated metadata. When reflection is disabled (Native AOT: JsonSerializer.IsReflectionEnabledByDefault == false) and a different IH5_Info implementation is passed, a NotSupportedException is thrown because the custom type has no generated JSON metadata.","triggerScenarios":"Publishing with Native AOT (PublishAot=true) and calling the payment/H5 request path with a custom class implementing IH5_Info instead of one of the three supported built-in scene types.","commonSituations":"Developers write their own IH5_Info implementation to add a custom wap_url/app_id scene; it works in normal (reflection-enabled) builds but crashes after switching to AOT/trimmed deployment.","solutions":["Switch to the built-in H5_Info_IOS, H5_Info_Android, or H5_Info_WAP types that match your scenario.","If a custom type is truly needed, add it to the JsonSerializerContext ([JsonSerializable]) and extend serialization accordingly.","Test under AOT publish settings before deploying; reflection-only paths fail only there."],"exampleFix":"// before\nIH5_Info h5 = new MyCustomH5Info(); // custom class\n// after\nIH5_Info h5 = new H5_Info_WAP { Type = \"WAP\", WapUrl = \"https://example.com\", WapName = \"Example\" };","handlingStrategy":"type-guard","validationCode":"// C#\nbool isAotSafeH5(IH5_Info h5) => h5 is H5_Info_IOS or H5_Info_Android or H5_Info_WAP;","typeGuard":"bool IsBuiltInH5Info(IH5_Info v) => v is H5_Info_IOS or H5_Info_Android or H5_Info_WAP;","tryCatchPattern":"try { json = TenPayJsonSerializer.SerializeCustomH5Info(h5Info); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Native AOT\")) { log.LogError(\"Replace {Type} with a built-in H5_Info_* type\", h5Info.GetType().FullName); }","preventionTips":["Only use H5_Info_IOS / H5_Info_Android / H5_Info_WAP","Run AOT publish builds in CI for payment flows","Avoid subclassing IH5_Info unless you also register it in a JsonSerializerContext"],"tags":["native-aot","json-serialization","weixin-tenpay","h5"],"backgroundTag":"unsupported-operation","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"}