{"record":{"id":"67e75a5eec8c2db6","repo":"dotnet/wpf","slug":"invalidvaluetype1","errorCode":null,"errorMessage":"InvalidValueType1","messagePattern":"InvalidValueType1","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":807,"sourceCode":"                }\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            }\n            else if (id == KnownIds.StylusTip)\n            {\n                Type valueType = value.GetType();\n                bool fStylusTipType = ( valueType == typeof(StylusTip) );\n                bool fIntType = ( valueType == typeof(int) );\n\n                if ( !fStylusTipType && !fIntType )\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(StylusTip), typeof(int)), nameof(value));\n                }\n                else if ( !StylusTipHelper.IsDefined((StylusTip)value) )\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueOfType, value, typeof(StylusTip)), nameof(value));\n                }\n            }\n            else if (id == KnownIds.StylusTipTransform)\n            {\n                //\n                // StylusTipTransform gets serialized as a String, but at runtime is a Matrix\n                //\n                Type t = value.GetType();\n                if ( t != typeof(String) && t != typeof(Matrix) )\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(String), typeof(Matrix)), nameof(value));\n                }\n                else if ( t == typeof(Matrix) )\n                {","sourceCodeStart":789,"sourceCodeEnd":825,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L789-L825","documentation":"For KnownIds.StylusTip, ExtendedPropertySerializer accepts only a StylusTip enum value or an int (for round-tripping serialized data). Any other value type throws ArgumentException with SR.InvalidValueType1. A valid-typed value that is not a defined StylusTip member throws InvalidValueOfType (see next).","triggerScenarios":"Setting the StylusTip extended property to a string, bool, double, or other non-StylusTip/non-int type and then serializing the ink / validating extended properties.","commonSituations":"Persisting stylus tip as a string name of the enum; deserializing user data into extended properties with wrong types; cross-version data where StylusTip was stored as a different numeric type.","solutions":["Assign a StylusTip enum member (StylusTip.Ellipse or StylusTip.Rectangle) as the value","If you have an int from serialized data, keep it as int (allowed), not another numeric type like long or byte","Validate the value type with a guard before adding it to ExtendedProperties"],"exampleFix":"// before\ndrawingAttributes[KnownIds.StylusTip] = \"Ellipse\";\n// after\ndrawingAttributes[KnownIds.StylusTip] = StylusTip.Ellipse;","handlingStrategy":"type-guard","validationCode":"var v = props[KnownIds.StylusTip];\nbool ok = v is StylusTip || v is int;","typeGuard":"static bool IsValidStylusTipValue(object v) => v is StylusTip || v is int;","tryCatchPattern":"try { serializer.Serialize(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"StylusTip\")) { props[KnownIds.StylusTip] = StylusTip.Ellipse; }","preventionTips":["Store enum extended properties as the enum type","Keep raw ints only for deserialization round-trips","Type-check dictionary values before calling validation"],"tags":["wpf","ink","argumentexception","extended-properties"],"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"}