dotnet/wpf · error · ArgumentException

SR.InvalidDocumentPropertyType (type)

Error message

SR.InvalidDocumentPropertyType (type)

What it means

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.

Solutions

  1. Convert the value to a supported type (string, DateTime, int, short, bool) before assigning.
  2. Check PackageProperties property docs for the expected CLR type per property.
  3. Join collections into a single delimited string (as Office does for keywords).
  4. Add a mapping layer that normalizes incoming values before assignment.

Example fix

// before
pkg.PackageProperties.Keywords = new List<string> { "a", "b" }; // throws
// after
pkg.PackageProperties.Keywords = string.Join(",", new[] { "a", "b" });
Defensive patterns

Strategy: validation

Validate before calling

bool IsSupportedPropValue(object v) => v is string or int or short or bool or DateTime or long?;

Type guard

bool IsSupportedPropValue(object? v) => v is string or bool or DateTime or int or short;

Try / catch

try { pkg.PackageProperties.Title = value; }
catch (ArgumentException ex) when (ex.ParamName == "propVal") { pkg.PackageProperties.Title = value?.ToString(); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/7d202731d34eb423. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs:731

                        pszVal = Marshal.AllocCoTaskMem(checked(nLen + 1));  //The extra one byte is for the string terminator null.

                        Marshal.Copy(byteArray, 0, pszVal, nLen);
                        Marshal.WriteByte(pszVal, nLen, 0);     //Put the string terminator null at the end of the array.
                    }

                    vals[0].vt = VARTYPE.VT_LPSTR;
                    vals[0].union.pszVal = pszVal;
                }
                else if (propVal is DateTime)
                {
                    // set FileTime as an Int64 to avoid pointer operations
                    vals[0].vt = VARTYPE.VT_FILETIME;
                    vals[0].union.hVal = ((DateTime)propVal).ToFileTime();
                }
                else
                {
                    throw new ArgumentException(
                                SR.Format(SR.InvalidDocumentPropertyType, propVal.GetType().ToString()),
                                nameof(propVal));
                }

                //
                // Again, we can just let it throw on failure; no non-zero success codes. It won't throw
                // if the property doesn't exist.
                //
                ps.WriteMultiple(1, propSpecs, vals, 0);
            }
            finally
            {
                if (pszVal != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pszVal);
                }
            }
        }

View on GitHub (pinned to 81131a70a4)