{"record":{"id":"f8a14b6b61cab91e","repo":"dotnet/wpf","slug":"notsupportedexception-resourcecontainer","errorCode":null,"errorMessage":"NotSupportedException","messagePattern":"NotSupportedException","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourceContainer.cs","lineNumber":346,"sourceCode":"\n        #endregion Private Members\n\n        //------------------------------------------------------\n        //\n        //  Uninteresting (but required) overrides\n        //\n        //------------------------------------------------------\n\n        #region Uninteresting (but required) overrides\n\n        protected override PackagePart CreatePartCore(Uri uri, string contentType, CompressionOption compressionOption)\n        {\n            return null;\n        }\n\n        protected override void DeletePartCore(Uri uri)\n        {\n            throw new NotSupportedException();\n        }\n\n        protected override PackagePart[] GetPartsCore()\n        {\n            throw new NotSupportedException();\n        }\n\n        protected override void FlushCore()\n        {\n            throw new NotSupportedException();\n        }\n\n        #endregion\n    }\n}\n","sourceCodeStart":328,"sourceCodeEnd":362,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourceContainer.cs#L328-L362","documentation":"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.","triggerScenarios":"Calling Package.DeletePart (directly or via DeletePart) on the resource Package (pack://application:...) to remove an application resource part.","commonSituations":"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.","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."],"exampleFix":"// before\npackage.DeletePart(partUri);\n// after\nif (!(package is ResourceContainer))\n    package.DeletePart(partUri);","handlingStrategy":"type-guard","validationCode":"if (package is ResourceContainer)\n    throw new InvalidOperationException(\"Application resource package is read-only\");\npackage.DeletePart(partUri);","typeGuard":"static bool IsDeletablePackage(Package package) => package is not ResourceContainer;","tryCatchPattern":"try\n{\n    package.DeletePart(partUri);\n}\ncatch (NotSupportedException)\n{\n    // resource package is read-only; use a writable package instead\n}","preventionTips":["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"],"tags":["wpf","package","read-only","not-supported"],"backgroundTag":"operation-not-supported","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}