{"record":{"id":"7662d422bbd5334d","repo":"dotnet/wpf","slug":"propspec-union-selector-is-unrecognized","errorCode":null,"errorMessage":"PROPSPEC union selector is unrecognized.","messagePattern":"PROPSPEC union selector is unrecognized\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/ManagedFilter.cs","lineNumber":47,"sourceCode":"        /// <value></value>\n        internal PropSpecType PropType\n        {\n            get\n            {\n                return _propType;\n            }\n// The following code is not being compiled, but should not be removed; since some container-filter\n// plug-in (e.g. metadata) may use it in future.\n#if false\n            set\n            {\n                switch (value)\n                {\n                    case PropSpecType.Id: break;\n                    case PropSpecType.Name: break;\n\n                    default:\n                        throw new ArgumentException(SR.FilterPropSpecUnknownUnionSelector, \"propSpec\");\n                }\n                _propType = value;\n            }\n#endif\n        }\n\n        /// <summary>\n        /// Property name (only valid if PropType is Name\n        /// </summary>\n        /// <value></value>\n        internal string PropName\n        {\n            get\n            {\n                System.Diagnostics.Debug.Assert(_propType == PropSpecType.Name, \"ManagedPropSpec.PropName - PropName only meaningful if PropType is type string\");\n                return _name;\n            }\n            set","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/ManagedFilter.cs#L29-L65","documentation":"ManagedFilter's ManagedPropSpec validates the PropSpecType union selector: only Id and Name are supported. Setting any other PROPSPEC selector (e.g., pointer-based lpwstr variants or other union members) throws ArgumentException because the managed wrapper cannot represent it.","triggerScenarios":"Constructing a ManagedPropSpec or setting its PropType to a PropSpecType value other than PropSpecType.Id or PropSpecType.Name.","commonSituations":"Marshaling native PROPSPEC structs from IFilter/property-system code that uses numeric/pointer selectors; copy-pasting property-spec code using FullPropSpec types not covered by the wrapper.","solutions":["Use only PropSpecType.Id (property ID) or PropSpecType.Name (string name) selectors.","Convert unsupported selectors before passing: resolve numeric IDs or names on the caller side.","Catch ArgumentException from the PropType setter and map/normalize the spec type first."],"exampleFix":"// before\nspec.PropType = PropSpecType.Pointer; // throws\n// after\nspec.PropType = PropSpecType.Id;\nspec.PropId = 2; // or use PropSpecType.Name with a string name","handlingStrategy":"validation","validationCode":"if (propSpec.Type != PropSpecType.Id && propSpec.Type != PropSpecType.Name) throw new ArgumentException(\"Only Id or Name PROPSPEC selectors are supported\", nameof(propSpec));","typeGuard":"static bool IsSupportedPropSpec(PropSpec s) => s.Type == PropSpecType.Id || s.Type == PropSpecType.Name;","tryCatchPattern":"try { wrapper.PropType = spec.Type; } catch (ArgumentException) { /* normalize to Id/Name or skip */ }","preventionTips":["Whitelist PropSpecType.Id and PropSpecType.Name in property-spec construction","Reject or convert exotic native PROPSPEC selectors at the interop boundary"],"tags":["com","propspec","invalid-enum-value","interop"],"backgroundTag":"unsupported-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"}