{"record":{"id":"d1d0c08750ce4199","repo":"microsoft/aspire","slug":"packed-histogram-data-length-must-be-a-multiple-of-8-bytes","errorCode":null,"errorMessage":"Packed histogram data length must be a multiple of 8 bytes.","messagePattern":"Packed histogram data length must be a multiple of 8 bytes\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Dashboard/Otlp/Storage/SqliteTelemetryRepository.Metrics.Writes.cs","lineNumber":639,"sourceCode":"        return values;\n    }\n\n    private static double[] UnpackDoubleValues(ReadOnlySpan<byte> bytes)\n    {\n        ValidatePackedValueLength(bytes);\n        var values = new double[bytes.Length / sizeof(double)];\n        for (var i = 0; i < values.Length; i++)\n        {\n            values[i] = BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64LittleEndian(bytes[(i * sizeof(double))..]));\n        }\n        return values;\n    }\n\n    private static void ValidatePackedValueLength(ReadOnlySpan<byte> bytes)\n    {\n        if (bytes.Length % sizeof(long) != 0)\n        {\n            throw new InvalidOperationException(\"Packed histogram data length must be a multiple of 8 bytes.\");\n        }\n    }\n\n    private void QueueMetricExemplars(MetricPointBatch pointBatch, long pointId, IEnumerable<Exemplar> exemplars)\n    {\n        foreach (var exemplar in exemplars)\n        {\n            if (exemplar.TraceId is null || exemplar.SpanId is null)\n            {\n                continue;\n            }\n            var value = exemplar.HasAsDouble ? exemplar.AsDouble : exemplar.AsInt;\n            if (!double.IsFinite(value))\n            {\n                continue;\n            }\n            var startTicks = OtlpHelpers.UnixNanoSecondsToDateTime(exemplar.TimeUnixNano).Ticks;\n            pointBatch.Exemplars.TryAdd(","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Dashboard/Otlp/Storage/SqliteTelemetryRepository.Metrics.Writes.cs#L621-L657","documentation":"Histogram exemplar or bound values are stored packed as fixed-width 8-byte (long/double) values. ValidatePackedValueLength, called from UnpackUInt64Values and UnpackDoubleValues, throws InvalidOperationException when the byte blob read from storage is not a multiple of sizeof(long), meaning the stored data is truncated or corrupt.","triggerScenarios":"UnpackUInt64Values or UnpackDoubleValues reads a packed histogram value column whose byte length is not a multiple of 8, e.g. during metric reads that unpack exemplar or histogram data.","commonSituations":"Database rows written by an older/newer schema writing packed data differently; corrupted or truncated SQLite files; manually migrated data where blobs were copied partially.","solutions":["Restore telemetry storage from a healthy backup or clear the dashboard telemetry store and let it re-ingest.","Verify the SQLite file integrity (e.g. PRAGMA integrity_check) and fix disk/storage issues.","Ensure the dashboard reading the data matches the version that wrote it.","If reproducible, capture the offending blob length and file an issue."],"exampleFix":"// after detecting the issue, reset storage so corrupt packed blobs are dropped:\n// dotnet aspire dashboard --data-dir <new-or-cleared-dir>\n// before\nvar dataDir = \"/shared/old-telemetry\"; // possibly corrupt\n// after\nvar dataDir = \"/home/user/.aspire/dashboard-telemetry\"; // fresh store","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var data = await repo.GetMetricsAsync(query);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"multiple of 8 bytes\"))\n{\n    logger.LogError(ex, \"Corrupt packed histogram data; resetting telemetry storage.\");\n    ResetTelemetryStore();\n}","preventionTips":["Run PRAGMA integrity_check if telemetry data seems off.","Don't copy/truncate telemetry database files manually.","Keep dashboard and storage versions in sync."],"tags":["metrics","storage","corruption","histogram"],"backgroundTag":"checksum-mismatch","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}