dotnet/wpf · error · FileFormatException

SR.XpsValidatingLoaderUnsupportedMimeType

Error message

SR.XpsValidatingLoaderUnsupportedMimeType

What it means

XpsSchema.GetSchema looks up a static registry of known XPS Content Types (FixedDocumentSequence, FixedDocument, FixedPage, ResourceDictionary). If the supplied ContentType is not one of the registered XPS schema MIME types, a FileFormatException is thrown because the validating loader cannot find a schema to validate the part against.

Solutions

  1. Only feed parts whose Content Type is one of the supported application/vnd.ms-package.xps-* types to the XPS validating loader.
  2. Fix the part's Content Type in [Content_Types].xml (or via part.ContentType) to match the actual XPS markup type.
  3. Exclude non-XPS parts from validation and load them through the regular packaging APIs instead.
  4. Check for typos/case errors in the MIME type string; use ContentType.StrongComparer semantics (exact type/subtype).

Example fix

// before
part.ContentType = "application/xps-fixedpage+xml"; // wrong MIME
// after
part.ContentType = "application/vnd.ms-package.xps-fixedpage+xml";
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> Supported = new(StringComparer.OrdinalIgnoreCase) {
    "application/vnd.ms-package.xps-fixeddocumentsequence+xml",
    "application/vnd.ms-package.xps-fixeddocument+xml",
    "application/vnd.ms-package.xps-fixedpage+xml",
    "application/vnd.ms-package.xps-resourcedictionary+xml" };
if (!Supported.Contains(part.ContentType))
    throw new InvalidOperationException($"Part {part.Uri} has unsupported Content Type {part.ContentType}");

Type guard

static bool IsXpsSchemaPart(PackagePart p) =>
    p.ContentType.StartsWith("application/vnd.ms-package.xps-", StringComparison.OrdinalIgnoreCase) && p.ContentType.EndsWith("+xml", StringComparison.OrdinalIgnoreCase);

Try / catch

try { var schema = XpsSchema.GetSchema(contentType); ValidateWith(schema); }
catch (FileFormatException) { /* part is not an XPS schema part: route to generic OPC handling */ }

Prevention

When it happens

Trigger: Passing a ContentType to GetSchema (directly or via the XPS validating loader when opening a package) whose type/subtype is not one of application/vnd.ms-package.xps-* — e.g. a random XML part, an image part, or a typo'd MIME type in [Content_Types].xml.

Common situations: Custom OPC packages that include XML parts which are not XPS markup; hand-edited [Content_Types].xml with an incorrect MIME string; attempts to validate arbitrary markup parts with the XPS loader; case/format mistakes in the Content Type string.

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/6a5878d302da7daa. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs:324

                {
                    return true;
                }
            }
            return false;
        }

        public virtual string [] ExtractUriFromAttr(string attrName, string attrValue)
        {
            return null;
        }

        public static XpsSchema GetSchema(ContentType mimeType)
        {
            XpsSchema schema = null;

            if (!_schemas.TryGetValue(mimeType, out schema))
            {
                throw new FileFormatException(SR.XpsValidatingLoaderUnsupportedMimeType);
            }

            return schema;
        }

        private static readonly Dictionary<ContentType, XpsSchema> _schemas = new Dictionary<ContentType, XpsSchema>(new ContentType.StrongComparer());
        private Hashtable _requiredResourceMimeTypes = new Hashtable(11);
    }

    internal class XpsS0Schema:XpsSchema
    {
        // When creating a new schema, add a static member to XpsSchemaValidator to register it.
        protected
        XpsS0Schema()
        {
        }

        public override XmlReaderSettings GetXmlReaderSettings()

View on GitHub (pinned to 81131a70a4)