{"record":{"id":"5e974ef55195bc20","repo":"dotnet/wpf","slug":"sr-modificationearlierthancreation","errorCode":null,"errorMessage":"SR.ModificationEarlierThanCreation","messagePattern":"SR\\.ModificationEarlierThanCreation","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs","lineNumber":140,"sourceCode":"        public Annotation(XmlQualifiedName annotationType, Guid id, DateTime creationTime, DateTime lastModificationTime)\n        {\n            ArgumentNullException.ThrowIfNull(annotationType);\n            if (String.IsNullOrEmpty(annotationType.Name))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"annotationType.Name\");//needs better message\n            }\n            if (String.IsNullOrEmpty(annotationType.Namespace))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"annotationType.Namespace\");//needs better message\n            }\n\n            if (id.Equals(Guid.Empty))\n            {\n                throw new ArgumentException(SR.InvalidGuid, nameof(id));\n            }\n            if (lastModificationTime.CompareTo(creationTime) < 0)\n            {\n                throw new ArgumentException(SR.ModificationEarlierThanCreation, nameof(lastModificationTime));\n            }\n            _id = id;\n            _typeName = annotationType;\n\n            _created = creationTime;\n            _modified = lastModificationTime;\n\n            Init();\n        }\n\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //\n        //  Public Methods\n        //\n        //------------------------------------------------------\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs#L122-L158","documentation":"Annotation's constructor enforces that lastModificationTime is not earlier than creationTime, throwing ArgumentException with SR.ModificationEarlierThanCreation. The annotation's audit timestamps must be chronologically consistent. Passing a modification time before creation violates this invariant.","triggerScenarios":"Calling the public Annotation constructor where lastModificationTime.CompareTo(creationTime) < 0, e.g. creationTime = DateTime.Now and lastModificationTime = an earlier stored time, or mixing UTC and local DateTime values.","commonSituations":"Loading annotations persisted by another system with clock skew; timezone conversion mistakes making modified appear earlier than created; defaulting creationTime to DateTime.Now while restoring an old modified value.","solutions":["Pass timestamps in a consistent order: modified must be >= created","Normalize both values to UTC (DateTimeKind.Utc) before constructing","Clamp lastModificationTime to creationTime when loading legacy data: use DateTimeHelper.Max"],"exampleFix":"// before\nvar ann = new Annotation(type, id, DateTime.Now, storedModifiedTime /* older, local time */);\n// after\nDateTime created = storedCreatedTime.ToUniversalTime();\nDateTime modified = storedModifiedTime.ToUniversalTime();\nif (modified < created) modified = created;\nvar ann = new Annotation(type, id, created, modified);","handlingStrategy":"validation","validationCode":"DateTime created = creationTime.ToUniversalTime();\nDateTime modified = lastModificationTime.ToUniversalTime();\nif (modified < created) modified = created;\nvar annotation = new Annotation(type, id, created, modified);","typeGuard":"bool AreTimesConsistent(DateTime created, DateTime modified) => modified >= created;","tryCatchPattern":"try\n{\n    var ann = new Annotation(type, id, created, modified);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogWarning(ex, \"Annotation timestamps inconsistent; clamping modified time\");\n    modified = created;\n    ann = new Annotation(type, id, created, modified);\n}","preventionTips":["Normalize all annotation timestamps to UTC to avoid timezone-induced inversion","Use the same clock source for creation and modification times","Clamp legacy data before constructing Annotation instances"],"tags":["wpf","annotations","datetime"],"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"}