{"record":{"id":"076bed8f07ca731d","repo":"dotnet/wpf","slug":"invalidvalueoftype","errorCode":null,"errorMessage":"InvalidValueOfType","messagePattern":"InvalidValueOfType","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":811,"sourceCode":"                // 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                {\n                    Matrix matrix = (Matrix)value;\n                    if ( !matrix.HasInverse )\n                    {\n                        throw new ArgumentException(SR.MatrixNotInvertible, nameof(value));","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L793-L829","documentation":"For KnownIds.StylusTip, once the value is a StylusTip (or boxed int cast to StylusTip), ExtendedPropertySerializer checks StylusTipHelper.IsDefined. If the value is not a defined StylusTip enum member, an ArgumentException with SR.InvalidValueOfType is thrown.","triggerScenarios":"Storing an out-of-range or undefined numeric value as StylusTip (e.g. (StylusTip)99 or an int outside the defined range) in the extended properties and serializing/validating.","commonSituations":"Casting arbitrary ints from external files/user input to StylusTip; corrupt or hand-edited ink data; enum definitions changed between framework versions.","solutions":["Ensure the numeric value maps to a defined StylusTip member before assigning (use Enum.IsDefined)","Sanitize deserialized data to a default (StylusTip.Ellipse) when undefined","Catch ArgumentException and skip/repair the offending extended property"],"exampleFix":"// before\nattrs[KnownIds.StylusTip] = (StylusTip)rawInt;\n// after\nvar tip = Enum.IsDefined(typeof(StylusTip), rawInt) ? (StylusTip)rawInt : StylusTip.Ellipse;\nattrs[KnownIds.StylusTip] = tip;","handlingStrategy":"validation","validationCode":"int raw = ...;\nif (!Enum.IsDefined(typeof(StylusTip), raw)) raw = (int)StylusTip.Ellipse;","typeGuard":"static bool IsDefinedStylusTip(StylusTip t) => t is StylusTip.Ellipse or StylusTip.Rectangle;","tryCatchPattern":"try { serializer.Serialize(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"StylusTip\")) { /* sanitize and retry or skip */ }","preventionTips":["Sanitize all externally sourced enum values with Enum.IsDefined","Default unknown enum values instead of casting blindly","Test serialization with boundary enum values"],"tags":["wpf","ink","argumentexception","enum"],"backgroundTag":"invalid-enum-value","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"}