{"record":{"id":"4879139cdd23b8a0","repo":"dotnet/wpf","slug":"sr-image-propertynotsupported","errorCode":null,"errorMessage":"SR.Image_PropertyNotSupported","messagePattern":"SR\\.Image_PropertyNotSupported","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/PropVariant.cs","lineNumber":309,"sourceCode":"                else if (value is String[])\n                {\n                    Init (value as String[], false);\n                }\n                else if (value is bool[])\n                {\n                    bool[] boolArray =value as bool[];\n                    short[] array = new short[boolArray.Length];\n\n                    for (int i=0; i<boolArray.Length; i++)\n                    {\n                        array[i] = (short) (boolArray[i] ? -1 : 0);\n                    }\n\n                    InitVector(array, typeof(short), VarEnum.VT_BOOL);\n                }\n                else\n                {\n                    throw new System.InvalidOperationException(SR.Image_PropertyNotSupported);\n                }\n            }\n            else\n            {\n                Type type = value.GetType();\n\n                if (value is String)\n                {\n                    varType = (ushort) VarEnum.VT_LPWSTR;\n                    pwszVal = Marshal.StringToCoTaskMemUni(value as String);\n                }\n                else if (type == typeof(sbyte))\n                {\n                    varType = (ushort) VarEnum.VT_I1;\n                    cVal = (sbyte) value;\n                }\n                else if (type == typeof(byte))\n                {","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/PropVariant.cs#L291-L327","documentation":"PropVariant.Init converts managed values into OLE PROPVARIANT representations. When a value of an unsupported managed type arrives in the branch that already handled known array/vector cases, it throws InvalidOperationException with Image_PropertyNotSupported: WPF metadata properties support only a fixed set of types.","triggerScenarios":"BitmapMetadata.SetQuery (or SetPropertyValue paths) supplying a value whose runtime type falls through PropVariant.Init's supported-type switch after the vector/array branch — e.g. custom structs, DateTime arrays of odd element types, or boxed unsupported types.","commonSituations":"Writing arbitrary .NET objects into EXIF/XMP queries; reading metadata generically, modifying values, and writing them back with a changed type; passing decimal/nullable types that WPF does not map.","solutions":["Convert the value to a supported type before SetQuery: byte, short, int, long, float, double, string, bool, or arrays of those.","For dates, store as string in the format the metadata field expects (EXIF date fields are strings).","Check the metadata query documentation for the field's native type and marshal accordingly (e.g. (ushort) for EXIF SHORT fields)."],"exampleFix":"// before\nmetadata.SetQuery(\"/app1/ifd/exif:{ushort=36867}\", DateTime.Now); // unsupported type\n\n// after\nmetadata.SetQuery(\"/app1/ifd/exif:{ushort=36867}\", DateTime.Now.ToString(\"yyyy:MM:dd HH:mm:ss\"));","handlingStrategy":"validation","validationCode":"bool supported = v is byte || v is short || v is int || v is long || v is float || v is double || v is string || v is bool;\nif (!supported) v = ConvertToSupported(v);","typeGuard":"static bool IsMetadataWritable(object v) => v is byte || v is short || v is int || v is long || v is float || v is double || v is string || v is bool;","tryCatchPattern":"try { metadata.SetQuery(q, value); } catch (InvalidOperationException ex) { /* coerce type and retry */ }","preventionTips":["Look up each metadata field's native type before writing and cast to it.","Avoid writing DateTime, Guid, decimal, or custom objects into metadata queries.","When round-tripping metadata, preserve the original type read from GetQuery."],"tags":["wpf","imaging","metadata","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"}