{"record":{"id":"e2db3905b0299793","repo":"reactiveui/refit","slug":"enum-typeof-tenum-does-not-use-an-unsigned-back","errorCode":null,"errorMessage":"Enum {typeof(TEnum)} does not use an unsigned backing type.","messagePattern":"Enum (.+?) does not use an unsigned backing type\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/Refit/EnumHelpers.cs","lineNumber":164,"sourceCode":"                TypeCode.SByte => Unsafe.As<TEnum, sbyte>(ref value),\n                TypeCode.Int16 => Unsafe.As<TEnum, short>(ref value),\n                TypeCode.Int32 => Unsafe.As<TEnum, int>(ref value),\n                TypeCode.Int64 => Unsafe.As<TEnum, long>(ref value),\n                _ => throw new JsonException($\"Enum {typeof(TEnum)} does not use a signed backing type.\")\n            };\n\n        /// <summary>Converts an enum value to an unsigned 64-bit number without boxing.</summary>\n        /// <param name=\"value\">The enum value.</param>\n        /// <returns>The unsigned numeric value.</returns>\n        /// <exception cref=\"JsonException\"><typeparamref name=\"TEnum\"/> is backed by a signed type, so it has no unsigned representation.</exception>\n        internal static ulong ToUInt64(TEnum value) =>\n            _underlyingTypeCode switch\n            {\n                TypeCode.Byte => Unsafe.As<TEnum, byte>(ref value),\n                TypeCode.UInt16 => Unsafe.As<TEnum, ushort>(ref value),\n                TypeCode.UInt32 => Unsafe.As<TEnum, uint>(ref value),\n                TypeCode.UInt64 => Unsafe.As<TEnum, ulong>(ref value),\n                _ => throw new JsonException($\"Enum {typeof(TEnum)} does not use an unsigned backing type.\")\n            };\n\n        /// <summary>Converts a numeric backing value to the enum type without boxing.</summary>\n        /// <typeparam name=\"TUnderlying\">The enum backing value type.</typeparam>\n        /// <param name=\"value\">The numeric backing value.</param>\n        /// <returns>The enum value.</returns>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        internal static TEnum ToEnum<TUnderlying>(TUnderlying value)\n            where TUnderlying : struct =>\n            Unsafe.As<TUnderlying, TEnum>(ref value);\n    }\n}\n","sourceCodeStart":146,"sourceCodeEnd":177,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit/EnumHelpers.cs#L146-L177","documentation":"Thrown by EnumHelpers.ToUInt64 when converting an enum value to an unsigned 64-bit number but the enum's underlying type is signed (sbyte/short/int/long). The switch only covers unsigned TypeCodes; a signed enum falls to the default arm. It is the mirror of error 37.","triggerScenarios":"ToUInt64 is invoked for an enum whose underlying type is signed (the default int-backed enum, for example). This is an internal helper; the serialization path is supposed to call ToUInt64 only for unsigned-backed enums, so reaching the throw indicates the signedness check was bypassed.","commonSituations":"Unreachable through ordinary Refit use. Could appear only if custom code calls EnumHelpers.Info<TEnum>.ToUInt64 on a signed-backed enum directly, or as an internal Refit bug.","solutions":["Do not call ToUInt64 on a signed-backed enum — use ToInt64, or check EnumHelpers.IsUnsignedBackingType first.","If it appears without custom EnumHelpers usage, file a Refit bug including the enum's declaration and underlying type.","If an unsigned numeric form is required for a signed enum, convert via ToInt64 then cast, rather than forcing ToUInt64."],"exampleFix":"// before — calling the unsigned helper on a signed (int) enum\npublic enum Flags { A, B } // backed by int\nulong v = EnumHelpers.Info<Flags>.ToUInt64(flags); // throws\n\n// after — use the matching signed helper\nlong v = EnumHelpers.Info<Flags>.ToInt64(flags);","handlingStrategy":"validation","validationCode":"// Only call ToUInt64 for unsigned-backed enums.\nstatic ulong SafeToUInt64<TEnum>(TEnum value) where TEnum : struct, Enum =>\n    EnumHelpers.Info<TEnum>.IsUnsignedBackingType(EnumHelpers.Info<TEnum>.UnderlyingTypeCode)\n        ? EnumHelpers.Info<TEnum>.ToUInt64(value)\n        : throw new InvalidOperationException(\"Enum is signed; use ToInt64.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Select the signedness-correct helper based on the enum's underlying type.","Avoid calling internal EnumHelpers helpers from application code.","Report as a Refit bug if it occurs during normal serialization of a standard enum."],"tags":["enum","json","enum-helpers","internal","signedness"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}