{"record":{"id":"5b8d0323aa6d754e","repo":"reactiveui/refit","slug":"unsupported-enum-backing-type-for-typeof-tenum","errorCode":null,"errorMessage":"Unsupported enum backing type for {typeof(TEnum)}.","messagePattern":"Unsupported enum backing type for (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/Refit/EnumHelpers.cs","lineNumber":122,"sourceCode":"            ReadJsonNumericValue(_underlyingTypeCode, ref reader);\n\n        /// <summary>Reads an undefined enum value using the supplied backing type code.</summary>\n        /// <param name=\"underlyingTypeCode\">The enum backing type code.</param>\n        /// <param name=\"reader\">The JSON reader positioned at a numeric token.</param>\n        /// <returns>The enum value represented by the numeric token.</returns>\n        /// <exception cref=\"JsonException\"><paramref name=\"underlyingTypeCode\"/> is not one of the integral type codes an enum can be backed by.</exception>\n        internal static TEnum ReadJsonNumericValue(TypeCode underlyingTypeCode, ref Utf8JsonReader reader) =>\n            underlyingTypeCode switch\n            {\n                TypeCode.SByte => ToEnum(checked((sbyte)reader.GetInt64())),\n                TypeCode.Byte => ToEnum(checked((byte)reader.GetUInt64())),\n                TypeCode.Int16 => ToEnum(checked((short)reader.GetInt64())),\n                TypeCode.UInt16 => ToEnum(checked((ushort)reader.GetUInt64())),\n                TypeCode.Int32 => ToEnum(checked((int)reader.GetInt64())),\n                TypeCode.UInt32 => ToEnum(checked((uint)reader.GetUInt64())),\n                TypeCode.Int64 => ToEnum(reader.GetInt64()),\n                TypeCode.UInt64 => ToEnum(reader.GetUInt64()),\n                _ => throw new JsonException($\"Unsupported enum backing type for {typeof(TEnum)}.\")\n            };\n\n        /// <summary>Writes an undefined enum value using the correct signedness for the enum backing type.</summary>\n        /// <param name=\"writer\">The JSON writer.</param>\n        /// <param name=\"value\">The enum value to write.</param>\n        internal static void WriteJsonNumericValue(Utf8JsonWriter writer, TEnum value)\n        {\n            if (IsUnsignedBackingType(_underlyingTypeCode))\n            {\n                writer.WriteNumberValue(ToUInt64(value));\n                return;\n            }\n\n            writer.WriteNumberValue(ToInt64(value));\n        }\n\n        /// <summary>Converts an enum value to a signed 64-bit number without boxing.</summary>\n        /// <param name=\"value\">The enum value.</param>","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit/EnumHelpers.cs#L104-L140","documentation":"Thrown by EnumHelpers.ReadJsonNumericValue when the enum's underlying TypeCode is not one of the supported integral types (sbyte, byte, short, ushort, int, uint, long, ulong). It is a defensive exhaustiveness check in the switch; in practice every valid .NET enum is backed by one of these, so reaching it implies a malformed or non-enum generic instantiation.","triggerScenarios":"The generic TEnum passed to EnumHelpers.Info<TEnum> is not a real enum (e.g. it was forced via reflection/Unsafe) or its Enum.GetUnderlyingType returned an unexpected TypeCode. ReadJsonNumericValue is hit when a JSON number is being mapped to the enum.","commonSituations":"Extremely rare for end users — essentially only if TEnum is mis-bound (abuse of generics, a build/trimming issue, or a custom converter using EnumHelpers on a non-enum type). It signals an internal contract violation more than a usage mistake.","solutions":["Ensure TEnum is a proper enum type (where TEnum : struct, Enum) and not a class/struct masquerading as one.","If you wrote a custom converter around EnumHelpers, validate TEnum.IsEnum and that its underlying type is a supported integral type before use.","Report it as a Refit bug if it occurs with a legitimate enum, since all standard enums should be covered."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify TEnum is a real enum with a supported backing type before use.\nstatic bool IsValidEnumType<TEnum>() where TEnum : struct\n{\n    var t = typeof(TEnum);\n    if (!t.IsEnum) return false;\n    var code = Type.GetTypeCode(Enum.GetUnderlyingType(t));\n    return code is TypeCode.SByte or TypeCode.Byte or TypeCode.Int16 or TypeCode.UInt16\n        or TypeCode.Int32 or TypeCode.UInt32 or TypeCode.Int64 or TypeCode.UInt64;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use EnumHelpers with genuine enum types constrained by `where TEnum : struct, Enum`.","If it triggers with a real enum, treat it as a Refit bug and report the enum's underlying type.","Don't abuse generics/Unsafe to feed non-enum types into enum helpers."],"tags":["enum","json","system-text-json","enum-helpers","internal"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}