{"record":{"id":"52087390caeb98d1","repo":"OrchardCMS/OrchardCore","slug":"unable-to-convert-stringvalue-to-datetime","errorCode":null,"errorMessage":"Unable to convert \"{stringValue}\" to DateTime.","messagePattern":"Unable to convert \"(.+?)\" to DateTime\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/DateTimeJsonConverter.cs","lineNumber":26,"sourceCode":"{\n    public static readonly DateTimeJsonConverter Instance = new();\n\n    public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (typeToConvert != typeof(DateTime))\n        {\n            throw new ArgumentException(\"Unexpected type to convert.\", nameof(typeToConvert));\n        }\n\n        if (!reader.TryGetDateTime(out var value))\n        {\n            var stringValue = reader.GetString();\n            if (DateTime.TryParse(stringValue, out value))\n            {\n                return value;\n            }\n\n            throw new JsonException($\"Unable to convert \\\"{stringValue}\\\" to DateTime.\");\n        }\n\n        return value;\n    }\n\n    public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)\n        => writer.WriteStringValue(value.ToString(\"yyyy-MM-ddTHH:mm:ssZ\", CultureInfo.InvariantCulture));\n}\n","sourceCodeStart":8,"sourceCodeEnd":35,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/DateTimeJsonConverter.cs#L8-L35","documentation":"The JSON token could not be parsed as a DateTime: Utf8JsonReader.TryGetDateTime failed (token is not an ISO 8601 string) and the fallback DateTime.TryParse on the raw string also failed. This fires when the JSON contains a date in a non-ISO format (e.g. 'dd/MM/yyyy') or a non-date value where a DateTime is expected.","triggerScenarios":"Thrown at src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/DateTimeJsonConverter.cs:26 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Serialize dates as ISO 8601 strings (yyyy-MM-ddTHH:mm:ssZ), the format this converter writes","Add a CultureInfo/DateTimeStyles-specific parse branch to the converter for the legacy format in use","Correct the producing side to emit a DateTime-compatible string instead of an arbitrary format"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}