{"record":{"id":"36dda8a9d77a8696","repo":"dotnet/efcore","slug":"unable-to-deserialize-a-sequence-from-model-metada","errorCode":null,"errorMessage":"Unable to deserialize a sequence from model metadata. See inner exception for details.","messagePattern":"Unable to deserialize a sequence from model metadata\\. See inner exception for details\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/Sequence.cs","lineNumber":729,"sourceCode":"                var data = new SequenceData();\n\n                // ReSharper disable PossibleInvalidOperationException\n                var position = 0;\n                data.Name = ExtractValue(value, ref position)!;\n                data.Schema = ExtractValue(value, ref position);\n                data.StartValue = (long)AsLong(ExtractValue(value, ref position)!)!;\n                data.IncrementBy = (int)AsLong(ExtractValue(value, ref position)!)!;\n                data.MinValue = AsLong(ExtractValue(value, ref position));\n                data.MaxValue = AsLong(ExtractValue(value, ref position));\n                data.ClrType = AsType(ExtractValue(value, ref position)!);\n                data.IsCyclic = AsBool(ExtractValue(value, ref position));\n                // ReSharper restore PossibleInvalidOperationException\n\n                return data;\n            }\n            catch (Exception ex)\n            {\n                throw new ArgumentException(RelationalStrings.BadSequenceString, ex);\n            }\n        }\n\n        private static string? ExtractValue(string value, ref int position)\n        {\n            position = value.IndexOf('\\'', position) + 1;\n\n            var end = value.IndexOf('\\'', position);\n\n            while (end + 1 < value.Length\n                   && value[end + 1] == '\\'')\n            {\n                end = value.IndexOf('\\'', end + 2);\n            }\n\n            var extracted = value[position..end].Replace(\"''\", \"'\");\n            position = end + 1;\n","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/Sequence.cs#L711-L747","documentation":"Thrown when SequenceData.Deserialize cannot parse a serialized sequence string from model metadata. The serialized form is a positional, single-quote-delimited tuple; any deviation in shape or content trips the inner exception which is wrapped as BadSequenceString.","triggerScenarios":"Sequence.SequenceData.Deserialize(value) catching any exception from ExtractValue/AsLong/AsType/AsBool during the fixed-order parse (Name, Schema, StartValue, IncrementBy, MinValue, MaxValue, ClrType, IsCyclic). Fires when the stored annotation string for a sequence is corrupt or hand-edited.","commonSituations":"Manually editing the Migrations/ModelSnapshot annotation string for a sequence; cross-version model snapshot incompatibility where the serialization format changed; truncated snapshot files; merging conflicts that mangled the sequence annotation.","solutions":["Re-scaffold the model snapshot so the sequence annotation is regenerated correctly (Add-Migration / dotnet ef migrations add with no changes to force a rebuild).","Restore the sequence annotation string from source control if a merge corrupted it.","Delete the corrupt sequence entry and re-add the sequence via HasSequence in OnModelCreating, then regenerate the snapshot.","Upgrade EF Core on all dev machines to the same version so serialization format matches."],"exampleFix":"// before: corrupt annotation in ModelSnapshot\nmodelBuilder.HasAnnotation(\"Relational:Sequence:OrderSeq\", \"'OrderSeq''dbo'1Xbad'\");\n\n// after: regenerate the snapshot, or restore the well-formed annotation\nmodelBuilder.HasAnnotation(\"Relational:Sequence:OrderSeq\", \"'OrderSeq''dbo'110019223372036854775807System.Int64'False'\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var seq = model.FindSequence(name); // triggers Deserialize if annotation is lazy\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Unable to deserialize a sequence\"))\n{\n    // The snapshot annotation is corrupt. Re-scaffold or restore from source control.\n    logger.LogError(ex, \"Corrupt sequence annotation in model snapshot.\");\n    throw;\n}","preventionTips":["Never hand-edit the serialized sequence annotation in the ModelSnapshot.","Keep the ModelSnapshot under source control and resolve merge conflicts carefully.","Use the same EF Core version across all developers and CI to avoid format drift.","After a version upgrade, regenerate the snapshot with a no-op migration."],"tags":["ef-core","relational-metadata","sequence","serialization","model-snapshot"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}