{"record":{"id":"63543f62906ad212","repo":"dotnet/wpf","slug":"time-format-string-is-not-valid","errorCode":null,"errorMessage":"Time format string is not valid.","messagePattern":"Time format string is not valid\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs","lineNumber":260,"sourceCode":"        /// hh = 24hr clock hour\n        /// mm = minutes (leading zero)\n        /// ss = seconds (leading zero)\n        /// .s = tenths of a second\n        /// </remarks>\n        public String TimeFormat\n        {\n            get\n            {\n                return _signatureTimeFormat;\n            }\n            set\n            {\n                ArgumentNullException.ThrowIfNull(value);\n\n                if (XmlSignatureProperties.LegalFormat(value))\n                    _signatureTimeFormat = value;\n                else\n                    throw new FormatException(SR.BadSignatureTimeFormatString);\n            }\n        }\n\n        //------------------------------------------------------\n        //\n        //  Public Fields\n        //\n        //------------------------------------------------------\n        /// <summary>\n        /// Name of signature origin part\n        /// </summary>\n        /// <value></value>\n        /// <remarks>This value may vary by Package because the name is not formally defined. While this \n        /// implementation will generally use the same default value, the value returned by this property will reflect \n        /// whatever origin is already present in the current Package (if any) which may vary between implementations.\n        /// </remarks>\n        public Uri SignatureOrigin\n        {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs#L242-L278","documentation":"The SignatureTimeFormat setter validates the time format string against XmlSignatureProperties.LegalFormat and throws FormatException (SR.BadSignatureTimeFormatString) when it does not match one of the accepted XML signature time formats (e.g. 'YYYY-MM-DD', 'YYYY-MM-DDThh:mm:ss' with optional timezone/fractional seconds).","triggerScenarios":"Assigning a .NET-style DateTime format string (e.g. 'yyyy-MM-dd HH:mm:ss' or 'o') to PackageDigitalSignatureManager.SignatureTimeFormat; the accepted syntax is the W3C XML Signature time format grammar, not DateTime.ToString patterns.","commonSituations":"Reusing a format string built for DateTime.ToString; using culture-specific formats; typos like missing 'T' separator or lowercase letters in the wrong places.","solutions":["Use one of the W3C XML signature time formats, e.g. \"yyyy-MM-ddThh:mm:ss\" with the required case/separators","Check the format against the XmlSignatureProperties.LegalFormat grammar before assigning","Catch FormatException around the assignment and fall back to the default format","Refer to the OPC/XmlDSig spec (xml:dateTime subset) rather than .NET custom format strings"],"exampleFix":"// before\nmanager.SignatureTimeFormat = DateTime.Now.ToString(\"yyyy-MM-dd HH:mm:ss\"); // space separator, not legal\n// after\nmanager.SignatureTimeFormat = \"yyyy-MM-ddThh:mm:ssZ\"; // legal XmlDSig time format","handlingStrategy":"validation","validationCode":"string[] legal = { \"yyyy-MM-dd\", \"yyyy-MM-ddThh:mm:ssZ\", \"yyyy-MM-ddThh:mm:ss.ffffffZ\" };\nif (Array.IndexOf(legal, format) < 0) throw new FormatException(\"SignatureTimeFormat is not a legal XmlDSig time format.\");","typeGuard":null,"tryCatchPattern":"try { manager.SignatureTimeFormat = format; }\ncatch (FormatException ex) { log.Error(\"Bad time format string\", ex); manager.SignatureTimeFormat = \"yyyy-MM-ddThh:mm:ssZ\"; }","preventionTips":["Use only documented W3C XML signature time formats","Do not reuse DateTime.ToString custom patterns for this property","Test the format assignment in a unit test before shipping"],"tags":["wpf","packaging","formatexception","time-format"],"backgroundTag":"invalid-date-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}