{"record":{"id":"248d01591db783cc","repo":"dotnet/wpf","slug":"sr-documentpropertiesdialogdocumentpropertiesmustexist","errorCode":null,"errorMessage":"SR.DocumentPropertiesDialogDocumentPropertiesMustExist","messagePattern":"SR\\.DocumentPropertiesDialogDocumentPropertiesMustExist","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentPropertiesDialog.cs","lineNumber":31,"sourceCode":"    /// <summary>\n    /// Dialog to view the current document properties.\n    /// </summary>\n    internal sealed partial class DocumentPropertiesDialog : DialogBaseForm\n    {\n        //------------------------------------------------------\n        //\n        //  Constructors\n        //\n        //------------------------------------------------------\n        #region Constructors\n        /// <summary>\n        /// Construct a new dialog, and populate it with data.\n        /// </summary>\n        internal DocumentPropertiesDialog() : base()\n        {\n            if (DocumentProperties.Current == null)\n            {\n                throw new NotSupportedException(SR.DocumentPropertiesDialogDocumentPropertiesMustExist);\n            }\n\n            PopulateDataFields();\n        }\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //\n        //  Protected Methods\n        //\n        //------------------------------------------------------\n        #region Protected Methods\n        /// <summary>\n        /// Called from the base constructor, this will setup all of the required string\n        /// resources for the dialog.\n        /// </summary>\n        protected override void ApplyResources()\n        {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentPropertiesDialog.cs#L13-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure DocumentProperties.Current is initialized (a document/package is loaded) before constructing the dialog.","Only show the properties dialog from the normal XPS viewer document lifecycle instead of constructing it manually.","Guard the call: check DocumentProperties.Current != null and skip or disable the Properties menu command when null."],"exampleFix":"// before\nvar dlg = new DocumentPropertiesDialog();\n// after\nif (DocumentProperties.Current == null) return; // or enable the command only when a document is loaded\nvar dlg = new DocumentPropertiesDialog();","handlingStrategy":"validation","validationCode":"bool canShowProperties = DocumentProperties.Current != null;","typeGuard":null,"tryCatchPattern":"try { var dlg = new DocumentPropertiesDialog(); dlg.Show(); }\ncatch (NotSupportedException) { /* no document loaded; disable command */ }","preventionTips":["Enable the document-properties command only when a document/package is loaded.","Never construct PresentationUI dialogs outside the XPS viewer lifecycle."],"tags":["wpf","xps","not-supported","document-properties"],"backgroundTag":"unsupported-operation","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"}