dotnet/wpf · error · NotSupportedException
NotSupportedException
Error message
NotSupportedException
What it means
ResourceContainer.DeletePartCore implements the Package-internal delete hook for the read-only application resource container. Resource parts come from the compiled application assembly and cannot be removed, so any delete request throws NotSupportedException. The resource container is deliberately read-only.
Solutions
- Do not delete parts from the application resource package; treat it as immutable.
- Maintain a separate writable Package (Package.Open) for parts that need mutation.
- Route deletions through a wrapper that checks package type and skips resource containers.
- Catch NotSupportedException if generic code may target the resource package.
Example fix
// before
package.DeletePart(partUri);
// after
if (!(package is ResourceContainer))
package.DeletePart(partUri); Defensive patterns
Strategy: type-guard
Validate before calling
if (package is ResourceContainer)
throw new InvalidOperationException("Application resource package is read-only");
package.DeletePart(partUri); Type guard
static bool IsDeletablePackage(Package package) => package is not ResourceContainer;
Try / catch
try
{
package.DeletePart(partUri);
}
catch (NotSupportedException)
{
// resource package is read-only; use a writable package instead
} Prevention
- Treat pack://application: packages as immutable
- Use Package.Open for mutable part storage
- Type-check the package before destructive operations
- Never reuse writable-package cleanup code on resource packages
When it happens
Trigger: Calling Package.DeletePart (directly or via DeletePart) on the resource Package (pack://application:...) to remove an application resource part.
Common situations: Code that generically cleans up package parts assuming a writable package; attempting to 'reset' a resource by deleting it at runtime; refactored code sharing a writable-package routine with the application resource package.
Related errors
- NotSupportedException
- SR.General_ObjectIsReadOnly
- SR.SetLengthNotSupported
- SR.StrokeCollectionIsReadOnly
- Stream does not support Write
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f8a14b6b61cab91e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourceContainer.cs:346
#endregion Private Members
//------------------------------------------------------
//
// Uninteresting (but required) overrides
//
//------------------------------------------------------
#region Uninteresting (but required) overrides
protected override PackagePart CreatePartCore(Uri uri, string contentType, CompressionOption compressionOption)
{
return null;
}
protected override void DeletePartCore(Uri uri)
{
throw new NotSupportedException();
}
protected override PackagePart[] GetPartsCore()
{
throw new NotSupportedException();
}
protected override void FlushCore()
{
throw new NotSupportedException();
}
#endregion
}
}
View on GitHub (pinned to 81131a70a4)