{"record":{"id":"7d202731d34eb423","repo":"dotnet/wpf","slug":"sr-invaliddocumentpropertytype-type","errorCode":null,"errorMessage":"SR.InvalidDocumentPropertyType (type)","messagePattern":"SR\\.InvalidDocumentPropertyType \\(type\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs","lineNumber":731,"sourceCode":"\n                        pszVal = Marshal.AllocCoTaskMem(checked(nLen + 1));  //The extra one byte is for the string terminator null.\n\n                        Marshal.Copy(byteArray, 0, pszVal, nLen);\n                        Marshal.WriteByte(pszVal, nLen, 0);     //Put the string terminator null at the end of the array.\n                    }\n\n                    vals[0].vt = VARTYPE.VT_LPSTR;\n                    vals[0].union.pszVal = pszVal;\n                }\n                else if (propVal is DateTime)\n                {\n                    // set FileTime as an Int64 to avoid pointer operations\n                    vals[0].vt = VARTYPE.VT_FILETIME;\n                    vals[0].union.hVal = ((DateTime)propVal).ToFileTime();\n                }\n                else\n                {\n                    throw new ArgumentException(\n                                SR.Format(SR.InvalidDocumentPropertyType, propVal.GetType().ToString()),\n                                nameof(propVal));\n                }\n\n                //\n                // Again, we can just let it throw on failure; no non-zero success codes. It won't throw\n                // if the property doesn't exist.\n                //\n                ps.WriteMultiple(1, propSpecs, vals, 0);\n            }\n            finally\n            {\n                if (pszVal != IntPtr.Zero)\n                {\n                    Marshal.FreeCoTaskMem(pszVal);\n                }\n            }\n        }","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs#L713-L749","documentation":"ArgumentException with message InvalidDocumentPropertyType(type) (paramName 'propVal') thrown by StorageBasedPackageProperties.SetOleProperty when the value assigned to a package property is not one of the supported CLR types (string, int, short, bool, DateTime, etc.). The setter cannot map the value to a VARTYPE for the OLE property stream.","triggerScenarios":"Assigning e.g. package.PackageProperties.Keywords = new[] {\"a\",\"b\"} or a decimal/long/custom object where only string, DateTime, or the specific numeric/bool types are supported for that property.","commonSituations":"Binding UI controls to PackageProperties so a collection or boxed type flows in; converting legacy settings objects directly to property values; assigning long where int is expected.","solutions":["Convert the value to a supported type (string, DateTime, int, short, bool) before assigning.","Check PackageProperties property docs for the expected CLR type per property.","Join collections into a single delimited string (as Office does for keywords).","Add a mapping layer that normalizes incoming values before assignment."],"exampleFix":"// before\npkg.PackageProperties.Keywords = new List<string> { \"a\", \"b\" }; // throws\n// after\npkg.PackageProperties.Keywords = string.Join(\",\", new[] { \"a\", \"b\" });","handlingStrategy":"validation","validationCode":"bool IsSupportedPropValue(object v) => v is string or int or short or bool or DateTime or long?;","typeGuard":"bool IsSupportedPropValue(object? v) => v is string or bool or DateTime or int or short;","tryCatchPattern":"try { pkg.PackageProperties.Title = value; }\ncatch (ArgumentException ex) when (ex.ParamName == \"propVal\") { pkg.PackageProperties.Title = value?.ToString(); }","preventionTips":["Check the documented CLR type for each PackageProperties property before assigning","Convert collections to delimited strings","Normalize values through a mapping layer"],"tags":["argumentexception","package-properties","metadata","type-mismatch"],"backgroundTag":"invalid-argument-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"}