{"record":{"id":"2178d66f63f5a703","repo":"microsoft/aspire","slug":"currentstateproperty-must-contain-a-json-object","errorCode":null,"errorMessage":"'{CurrentStateProperty}' must contain a JSON object.","messagePattern":"'(.+?)' must contain a JSON object\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Pipelines/Internal/FileDeploymentStateManager.cs","lineNumber":765,"sourceCode":"    {\n        var legacyFallbackDisabled = migrationState[LegacyFallbackDisabledProperty]?.GetValue<bool>() ?? false;\n        var legacyStateSnapshot = migrationState[LegacyStateProperty] switch\n        {\n            null => [],\n            JsonObject legacyState => legacyState,\n            _ => throw new InvalidDataException($\"'{LegacyStateProperty}' must be a JSON object.\")\n        };\n        var claimedSectionNames = migrationState[ClaimedSectionsProperty] switch\n        {\n            null => [],\n            JsonValue claimedSectionsValue => ParseClaimedSectionNames(claimedSectionsValue),\n            _ => throw new InvalidDataException($\"'{ClaimedSectionsProperty}' must be a JSON string.\")\n        };\n        var currentState = migrationState[CurrentStateProperty] switch\n        {\n            null => null,\n            JsonValue stateValue => JsonNode.Parse(stateValue.GetValue<string>())?.AsObject()\n                ?? throw new InvalidDataException($\"'{CurrentStateProperty}' must contain a JSON object.\"),\n            _ => throw new InvalidDataException($\"'{CurrentStateProperty}' must be a JSON string.\")\n        };\n\n        return new(legacyFallbackDisabled, legacyStateSnapshot, claimedSectionNames, currentState);\n    }\n\n    private static string[] ParseClaimedSectionNames(JsonValue claimedSectionsValue)\n    {\n        var claimedSectionNames = JsonSerializer.Deserialize<string?[]>(\n            claimedSectionsValue.GetValue<string>());\n        if (claimedSectionNames is null ||\n            claimedSectionNames.Any(string.IsNullOrWhiteSpace))\n        {\n            throw new InvalidDataException(\n                $\"'{ClaimedSectionsProperty}' must contain a JSON array of non-empty strings.\");\n        }\n\n        return [.. claimedSectionNames.Select(static sectionName => sectionName!)];","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Pipelines/Internal/FileDeploymentStateManager.cs#L747-L783","documentation":"The 'currentState' property of the migration state must be a JSON string that itself parses to a JSON object (state is stored serialized as a string). If the parsed value is null or not an object — or JsonNode.Parse fails to yield an object — InvalidDataException is thrown.","triggerScenarios":"Loading a migration state file where currentState is an empty string, or a string that parses to null/array/scalar rather than an object.","commonSituations":"A write that serialized the current state incorrectly or truncated the embedded JSON string; manual edits that emptied the string; schema drift between Aspire versions.","solutions":["Repair currentState to be a JSON string containing a valid JSON object (e.g. \"{}\"), or remove the property if the tooling treats null as no current state.","Delete the corrupt migration/state file and re-run so it is regenerated.","Restore from backup if the file contained real deployment state you need."],"exampleFix":"// before (state file)\n{ \"currentState\": \"\" }\n// after\n{ \"currentState\": \"{\\\"resources\\\":{}}\" }","handlingStrategy":"validation","validationCode":"// currentState must be a string whose content parses to a JSON object\nif (migrationState[\"currentState\"] is JsonValue v &&\n    (!v.TryGetValue<string>(out var s) || JsonNode.Parse(s) is not JsonObject))\n{\n    throw new InvalidDataException(\"currentState must be a JSON string containing a JSON object.\");\n}","typeGuard":"static bool HasValidCurrentState(JsonObject migrationState) =>\n    migrationState[\"currentState\"] is not JsonValue v\n    || (v.TryGetValue<string>(out var s) && JsonNode.Parse(s) is JsonObject);","tryCatchPattern":"try { await manager.LoadStateAsync(ct); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"currentState\") && ex.Message.Contains(\"JSON object\"))\n{\n    File.Move(statePath, statePath + \".corrupt\", overwrite: true);\n}","preventionTips":["Never write an empty string for currentState; use an escaped empty object (\"{}\") or omit the property.","Serialize embedded state with JsonSerializer and store it as a string.","Validate the file after any external tool touches it."],"tags":["json","state-file","migration","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}