dotnet/wpf · error · ArgumentException
InvalidValueType1
Error message
InvalidValueType1
What it means
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).
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
Example fix
// before drawingAttributes[KnownIds.StylusTip] = "Ellipse"; // after drawingAttributes[KnownIds.StylusTip] = StylusTip.Ellipse;
Defensive patterns
Strategy: type-guard
Validate before calling
var v = props[KnownIds.StylusTip]; bool ok = v is StylusTip || v is int;
Type guard
static bool IsValidStylusTipValue(object v) => v is StylusTip || v is int;
Try / catch
try { serializer.Serialize(...); }
catch (ArgumentException ex) when (ex.Message.Contains("StylusTip")) { props[KnownIds.StylusTip] = StylusTip.Ellipse; } Prevention
- Store enum extended properties as the enum type
- Keep raw ints only for deserialization round-trips
- Type-check dictionary values before calling validation
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- ExtendedProperty is already part of the…
- Global Custom Attribute tag embedded in ISF stream does not…
- GUID cannot be empty.
- InvalidMatrixContainsInfinity
- InvalidMatrixContainsNaN
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/67e75a5eec8c2db6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs:807
}
}
else if (id == KnownIds.DrawingFlags)
{
// ignore validation of flags
if (value.GetType() != typeof(DrawingFlags))
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(DrawingFlags)), nameof(value));
}
}
else if (id == KnownIds.StylusTip)
{
Type valueType = value.GetType();
bool fStylusTipType = ( valueType == typeof(StylusTip) );
bool fIntType = ( valueType == typeof(int) );
if ( !fStylusTipType && !fIntType )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(StylusTip), typeof(int)), nameof(value));
}
else if ( !StylusTipHelper.IsDefined((StylusTip)value) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueOfType, value, typeof(StylusTip)), nameof(value));
}
}
else if (id == KnownIds.StylusTipTransform)
{
//
// StylusTipTransform gets serialized as a String, but at runtime is a Matrix
//
Type t = value.GetType();
if ( t != typeof(String) && t != typeof(Matrix) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(String), typeof(Matrix)), nameof(value));
}
else if ( t == typeof(Matrix) )
{View on GitHub (pinned to 81131a70a4)