dotnet/wpf · error · FileFormatException

SR.RMProviderExceptionNoPublishLicense

Error message

SR.RMProviderExceptionNoPublishLicense

What it means

During InitializeMembers, the provider loads the publish license from the rights management envelope (rmInfo.LoadPublishLicense()); when it returns null a FileFormatException is thrown with SR.RMProviderExceptionNoPublishLicense. The protected package is malformed: the mandatory publish license is missing. This runs during IsProtected, InitializeEnvironment, and SetEncryptedPackage paths.

Solutions

  1. Verify the document is a complete, valid rights-managed package; re-obtain the original file.
  2. Regenerate/re-save the document with the original application to embed a valid publish license.
  3. Check that the envelope's RM metadata parts exist and are readable on disk (not blocked/truncated by sync or transfer tools).
  4. If you control the producer, fix the writer so a PublishLicense is always embedded when protecting a document.
Defensive patterns

Strategy: try-catch

Try / catch

try { provider.SetEncryptedPackage(packageStream); }
catch (FileFormatException) { /* treat document as corrupt/invalid RM package; ask user for original file */ }

Prevention

When it happens

Trigger: Opening/initializing a rights-managed compound document whose envelope contains no publish license — e.g., LoadPublishLicense returns null because the package part is absent, corrupt, or was stripped by a non-conforming producer.

Common situations: Opening a document produced by a buggy or third-party RM writer, a partially copied/truncated .xps/.baml protected package, or a file modified by tooling that removed RM metadata.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs:1278

    /// <summary>
    /// Initializes the necessary member variables.  This can be called more
    /// than once without ill effect.
    /// </summary>
    private void InitializeMembers()
    {
        if (_encryptedPackageEnvelope != null &&
            _publishLicenseFromEnvelope == null)
        {
            RightsManagementInformation rmInfo =
                _encryptedPackageEnvelope.RightsManagementInformation;
            PublishLicense publishLicense = null;

            publishLicense = rmInfo.LoadPublishLicense();

            if (publishLicense == null)
            {
                throw new FileFormatException(
                    SR.RMProviderExceptionNoPublishLicense);
            }

            _publishLicenseFromEnvelope = publishLicense;
            CurrentPublishLicense = publishLicense;
        }
    }

    /// <summary>
    /// Cleans up the SecureEnvironment member.
    /// </summary>
    private void CleanUpSecureEnvironment()
    {
        _secureEnvironment?.Dispose();
        _secureEnvironment = null;
    }

    /// <summary>

View on GitHub (pinned to 81131a70a4)