dotnet/wpf · error · XamlParseException

SR.TextEditorCopyPaste_EntryPartIsMissingInXamlPackage

Error message

SR.TextEditorCopyPaste_EntryPartIsMissingInXamlPackage

What it means

WpfPayload.ValidatePayload throws XamlParseException when a WPF payload package (a WPF-flavored XAML package on the clipboard or in a data object) contains no recognizable WPF entry part. GetWpfEntryPart returned null, meaning the package structure is not a valid WPF payload, so it cannot be parsed.

Solutions

  1. Check clipboard/DataObject.ContainsData(DataFormats.XamlPackage) and validate the payload before calling the parse path.
  2. Catch XamlParseException and fall back to other clipboard formats (Text, Html, Rtf) or DataFormats.Xaml.
  3. Re-copy the content from the source application so a fresh, intact WPF payload is produced.
  4. If serializing payloads yourself, always write the WPF entry part (WpfPayload.CreateWpfPayload) before storing the package.

Example fix

// before
var payload = WpfPayload.CreateFromDataObject(dataObject);
var part = payload.ValidatePayload(); // throws if missing
// after
if (!dataObject.GetDataPresent(DataFormats.XamlPackage))
    return; // use Text/Html fallback
try
{
    var part = payload.ValidatePayload();
}
catch (XamlParseException)
{
    // fall back to DataFormats.Text / Html
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!dataObject.GetDataPresent(DataFormats.XamlPackage))
    return FallbackToTextOrHtml(dataObject);

Try / catch

try { var part = payload.ValidatePayload(); }
catch (XamlParseException)
 call payload = FallbackToOtherFormats(dataObject); }

Prevention

When it happens

Trigger: Reading clipboard data with DataFormats.XamlPackage / WpfPayload where the clipboard content was not written by WPF, the package part named as the WPF entry is absent, or the package was truncated/corrupted between copy and paste.

Common situations: Pasting from non-WPF apps that put malformed XAML packages on the clipboard; clipboard content overwritten between copy and paste; third-party clipboard managers converting data formats; corrupted streams saved/restored from disk.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WpfPayload.cs:367

            catch (System.OutOfMemoryException)
            {
                xamlObject = null;
            }

            return xamlObject;
        }

        // Checks whether the WPF payload meets minimal structural requirements:
        // 1) Entry part exists
        // 2) All components have proper relationships established between source and target
        // Returns an entry part of the payload if it is valid; throws otherwise.
        private PackagePart ValidatePayload()
        {
            // Get the WPF entry part
            PackagePart xamlEntryPart = this.GetWpfEntryPart();
            if (xamlEntryPart == null)
            {
                throw new XamlParseException(SR.TextEditorCopyPaste_EntryPartIsMissingInXamlPackage);
            }

            //  Add more validation for package structure

            return xamlEntryPart;
        }

        private static int _wpfPayloadCount; // used to disambiguate between all acts of loading from different WPF payloads.

        // -------------------------------------------------------------
        //
        // Public Properties
        //
        // -------------------------------------------------------------

        #region Public Properties

        /// <summary>

View on GitHub (pinned to 81131a70a4)