{"record":{"id":"4ec24b8339e06b78","repo":"dotnet/wpf","slug":"the-only-ipersistfile-operation-supported-by-the-component","errorCode":null,"errorMessage":"The only IPersistFile operation supported by the component is Load.","messagePattern":"The only IPersistFile operation supported by the component is Load\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs","lineNumber":589,"sourceCode":"        /// <param name=\"stream\">The stream to which the object is saved. </param>\n        /// <param name=\"fClearDirty\">Indicates whether the dirty state is to be cleared. </param>\n        /// <remarks>\n        /// Expected error codes are described at\n        /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/html/b748b4f9-ef9c-486b-bdc4-4d23c4640ff7.asp\n        /// </remarks>\n        void IPersistStream.Save(MS.Internal.Interop.IStream stream, bool fClearDirty)\n        {\n            throw new COMException(SR.FilterIPersistStreamIsReadOnly, NativeMethods.STG_E_CANTSAVE);\n        }\n\n        /// <summary>\n        /// The purpose of this function when implemented by a persistent object is to return\n        /// the size in bytes of the stream needed to save the object.\n        /// Always returns COR_E_NOTSUPPORTED insofar as the filter does not use this interface for persistence.\n        /// </summary>\n        void IPersistStream.GetSizeMax(out Int64 pcbSize)\n        {\n            throw new NotSupportedException(SR.FilterIPersistFileIsReadOnly);\n        }\n\n        #endregion IPersistStream methods\n\n        #region Private methods\n\n        /// <summary>\n        /// Shared implementation for releasing package/encryptedPackage and underlying stream\n        /// </summary>\n        private void ReleaseResources()\n        {\n            if (_encryptedPackage != null)\n            {\n                _encryptedPackage.Close();\n                _encryptedPackage = null;\n            }\n            else\n            {","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs#L571-L607","documentation":"IPersistStream.GetSizeMax must return the size needed to persist the object, but the filter does not use this interface for persistence, so it throws NotSupportedException reusing the SR.FilterIPersistFileIsReadOnly message. It is an unsupported-operation stub rather than a state error.","triggerScenarios":"Calling IPersistStream.GetSizeMax(out pcbSize) on an XpsFilter instance.","commonSituations":"Marshaled clients that call GetSizeMax before Save in a standard persistence protocol; reflection-based test coverage of IPersistStream.","solutions":["Do not call GetSizeMax on the filter; it never saves via IPersistStream","Catch NotSupportedException around GetSizeMax for read-only components","Restructure persistence code to detect load-only components and skip save protocols"],"exampleFix":"// before\n((IPersistStream)filter).GetSizeMax(out long size);\n// after\ntry { ((IPersistStream)filter).GetSizeMax(out long size); }\ncatch (NotSupportedException)\n{\n    // read-only filter: skip IPersistStream save protocol\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ((IPersistStream)filter).GetSizeMax(out long size); }\ncatch (NotSupportedException)\n{ /* unsupported on read-only filter; skip save protocol */ }","preventionTips":["Do not call GetSizeMax on filters","Detect load-only persistence components before invoking save-side methods","Wrap generic persistence protocols in capability checks"],"tags":["com","unsupported","wpf","read-only"],"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"}