dotnet/wpf · error · NotSupportedException

SR.DocumentPropertiesDialogDocumentPropertiesMustExist

Error message

SR.DocumentPropertiesDialogDocumentPropertiesMustExist

What it means

DocumentPropertiesDialog's constructor throws NotSupportedException if DocumentProperties.Current is null. The dialog is a viewer bound to the application's current DocumentProperties instance; without a current instance there is no data to populate, so construction is intentionally unsupported.

Solutions

  1. Ensure DocumentProperties.Current is initialized (a document/package is loaded) before constructing the dialog.
  2. Only show the properties dialog from the normal XPS viewer document lifecycle instead of constructing it manually.
  3. Guard the call: check DocumentProperties.Current != null and skip or disable the Properties menu command when null.

Example fix

// before
var dlg = new DocumentPropertiesDialog();
// after
if (DocumentProperties.Current == null) return; // or enable the command only when a document is loaded
var dlg = new DocumentPropertiesDialog();
Defensive patterns

Strategy: validation

Validate before calling

bool canShowProperties = DocumentProperties.Current != null;

Try / catch

try { var dlg = new DocumentPropertiesDialog(); dlg.Show(); }
catch (NotSupportedException) { /* no document loaded; disable command */ }

Prevention

When it happens

Trigger: Instantiating new DocumentPropertiesDialog() (directly or via XpsDocument-based UI paths) when DocumentProperties.Current has never been initialized, e.g. before a package/XPS document has been associated with the document application.

Common situations: Developers reusing the internal PresentationUI document dialog classes outside the normal XPS viewer lifecycle, or invoking the properties dialog before the document pipeline established the current DocumentProperties.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentPropertiesDialog.cs:31

    /// <summary>
    /// Dialog to view the current document properties.
    /// </summary>
    internal sealed partial class DocumentPropertiesDialog : DialogBaseForm
    {
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------
        #region Constructors
        /// <summary>
        /// Construct a new dialog, and populate it with data.
        /// </summary>
        internal DocumentPropertiesDialog() : base()
        {
            if (DocumentProperties.Current == null)
            {
                throw new NotSupportedException(SR.DocumentPropertiesDialogDocumentPropertiesMustExist);
            }

            PopulateDataFields();
        }
        #endregion Constructors

        //------------------------------------------------------
        //
        //  Protected Methods
        //
        //------------------------------------------------------
        #region Protected Methods
        /// <summary>
        /// Called from the base constructor, this will setup all of the required string
        /// resources for the dialog.
        /// </summary>
        protected override void ApplyResources()
        {

View on GitHub (pinned to 81131a70a4)