dotnet/wpf · error · FormatException
Time format string is not valid.
Error message
Time format string is not valid.
What it means
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).
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
Example fix
// before
manager.SignatureTimeFormat = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // space separator, not legal
// after
manager.SignatureTimeFormat = "yyyy-MM-ddThh:mm:ssZ"; // legal XmlDSig time format Defensive patterns
Strategy: validation
Validate before calling
string[] legal = { "yyyy-MM-dd", "yyyy-MM-ddThh:mm:ssZ", "yyyy-MM-ddThh:mm:ss.ffffffZ" };
if (Array.IndexOf(legal, format) < 0) throw new FormatException("SignatureTimeFormat is not a legal XmlDSig time format."); Try / catch
try { manager.SignatureTimeFormat = format; }
catch (FormatException ex) { log.Error("Bad time format string", ex); manager.SignatureTimeFormat = "yyyy-MM-ddThh:mm:ssZ"; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Reusing a format string built for DateTime.ToString; using culture-specific formats; typos like missing 'T' separator or lowercase letters in the wrong places.
Related errors
- ' ' cannot contain the path delimiter: ' '.
- ' ' cannot start with the reserved character range…
- ' ' ID is not a valid XSD ID.
- ' ' is not a valid value for ' '.
- Can only countersign parts with Digital Signature…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/63543f62906ad212.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs:260
/// hh = 24hr clock hour
/// mm = minutes (leading zero)
/// ss = seconds (leading zero)
/// .s = tenths of a second
/// </remarks>
public String TimeFormat
{
get
{
return _signatureTimeFormat;
}
set
{
ArgumentNullException.ThrowIfNull(value);
if (XmlSignatureProperties.LegalFormat(value))
_signatureTimeFormat = value;
else
throw new FormatException(SR.BadSignatureTimeFormatString);
}
}
//------------------------------------------------------
//
// Public Fields
//
//------------------------------------------------------
/// <summary>
/// Name of signature origin part
/// </summary>
/// <value></value>
/// <remarks>This value may vary by Package because the name is not formally defined. While this
/// implementation will generally use the same default value, the value returned by this property will reflect
/// whatever origin is already present in the current Package (if any) which may vary between implementations.
/// </remarks>
public Uri SignatureOrigin
{View on GitHub (pinned to 81131a70a4)