dotnet/wpf · warning · NotSupportedException
The only IPersistFile operation supported by the component…
Error message
The only IPersistFile operation supported by the component is Load.
What it means
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.
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
Example fix
// before
((IPersistStream)filter).GetSizeMax(out long size);
// after
try { ((IPersistStream)filter).GetSizeMax(out long size); }
catch (NotSupportedException)
{
// read-only filter: skip IPersistStream save protocol
} Defensive patterns
Strategy: try-catch
Try / catch
try { ((IPersistStream)filter).GetSizeMax(out long size); }
catch (NotSupportedException)
{ /* unsupported on read-only filter; skip save protocol */ } Prevention
- Do not call GetSizeMax on filters
- Detect load-only persistence components before invoking save-side methods
- Wrap generic persistence protocols in capability checks
When it happens
Trigger: Calling IPersistStream.GetSizeMax(out pcbSize) on an XpsFilter instance.
Common situations: Marshaled clients that call GetSizeMax before Save in a standard persistence protocol; reflection-based test coverage of IPersistStream.
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/4ec24b8339e06b78.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs:589
/// <param name="stream">The stream to which the object is saved. </param>
/// <param name="fClearDirty">Indicates whether the dirty state is to be cleared. </param>
/// <remarks>
/// Expected error codes are described at
/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/html/b748b4f9-ef9c-486b-bdc4-4d23c4640ff7.asp
/// </remarks>
void IPersistStream.Save(MS.Internal.Interop.IStream stream, bool fClearDirty)
{
throw new COMException(SR.FilterIPersistStreamIsReadOnly, NativeMethods.STG_E_CANTSAVE);
}
/// <summary>
/// The purpose of this function when implemented by a persistent object is to return
/// the size in bytes of the stream needed to save the object.
/// Always returns COR_E_NOTSUPPORTED insofar as the filter does not use this interface for persistence.
/// </summary>
void IPersistStream.GetSizeMax(out Int64 pcbSize)
{
throw new NotSupportedException(SR.FilterIPersistFileIsReadOnly);
}
#endregion IPersistStream methods
#region Private methods
/// <summary>
/// Shared implementation for releasing package/encryptedPackage and underlying stream
/// </summary>
private void ReleaseResources()
{
if (_encryptedPackage != null)
{
_encryptedPackage.Close();
_encryptedPackage = null;
}
else
{View on GitHub (pinned to 81131a70a4)