{"record":{"id":"c11157962316f9b9","repo":"dotnet/wpf","slug":"invalidvaluetype","errorCode":null,"errorMessage":"InvalidValueType","messagePattern":"InvalidValueType","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":780,"sourceCode":"        #region Key/Value pair validation helpers\n        /// <summary>\n        /// Validates the data to be associated with a ExtendedProperty id\n        /// </summary>\n        /// <param name=\"id\">ExtendedProperty identifier</param>\n        /// <param name=\"value\">data</param>\n        /// <remarks>Ignores Ids that are not known (e.g. ExtendedProperties)</remarks>\n        internal static void Validate(Guid id, object value)\n        {\n            if (id == Guid.Empty)\n            {\n                throw new ArgumentException(SR.InvalidGuid);\n            }\n\n            if (id == KnownIds.Color)\n            {\n                if (!(value is System.Windows.Media.Color))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(System.Windows.Media.Color)), nameof(value));\n                }\n            }\n                // int attributes\n            else if (id == KnownIds.CurveFittingError)\n            {\n                if (!(value.GetType() == typeof(int)))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(int)), nameof(value));\n                }\n            }\n            else if (id == KnownIds.DrawingFlags)\n            {\n                // ignore validation of flags\n                if (value.GetType() != typeof(DrawingFlags))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(DrawingFlags)), nameof(value));\n                }\n            }","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L762-L798","documentation":"Thrown by ExtendedPropertySerializer.Validate when the known GUID (KnownIds.Color) is used but the stored value is not a System.Windows.Media.Color. Known GUIDs have fixed expected value types so the ISF encoder can serialize them; a wrong-typed value cannot be encoded correctly.","triggerScenarios":"Assigning an extended property under the Color known GUID with a non-Color value (e.g. a string like \"#FF0000\", an int, or a System.Drawing.Color from WinForms).","commonSituations":"Interop confusion between System.Drawing.Color and System.Windows.Media.Color; storing color as hex string in extended properties then serializing to ISF.","solutions":["Store a System.Windows.Media.Color value for the Color known GUID (convert first if needed).","If the source is a WinForms System.Drawing.Color, convert via Color.FromArgb(a,r,g,b) into Media.Color.","If the value is a string/int, choose a custom GUID for it instead of the Color known id, or parse it into a Media.Color."],"exampleFix":"// before\ndrawingAttributes.ExtendedProperties.Add(KnownIds.Color, \"#FF0000\");\n// after\nvar color = (Color)ColorConverter.ConvertFromString(\"#FF0000\");\ndrawingAttributes.ExtendedProperties.Add(KnownIds.Color, color);","handlingStrategy":"type-guard","validationCode":"if (id == KnownIds.Color && value is not System.Windows.Media.Color)\n    throw new ArgumentException(\"Color extended property requires System.Windows.Media.Color\", nameof(value));","typeGuard":"bool IsValidColorValue(object v) => v is System.Windows.Media.Color;","tryCatchPattern":"try { props.Add(KnownIds.Color, value); }\ncatch (ArgumentException ex) when (ex.ParamName == \"value\") { props.Add(KnownIds.Color, ConvertToMediaColor(value)); }","preventionTips":["Always store System.Windows.Media.Color for the Color known id","Convert System.Drawing.Color explicitly at interop boundaries","Add unit tests validating known-GUID value types"],"tags":["ink","extended-properties","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}