{"record":{"id":"fc5974f711707fd4","repo":"dotnet/wpf","slug":"notsupportedexception-siteoforigincontainer","errorCode":null,"errorMessage":"NotSupportedException","messagePattern":"NotSupportedException","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AppModel/SiteOfOriginContainer.cs","lineNumber":205,"sourceCode":"\n        #endregion\n\n\n        //------------------------------------------------------\n        //\n        //  Uninteresting (but required) overrides\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":187,"sourceCodeEnd":221,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AppModel/SiteOfOriginContainer.cs#L187-L221","documentation":"SiteOfOriginContainer is a read-only PackagingContainer representing the site of origin of an application. Deleting a part is not a meaningful operation for it, so DeletePartCore throws NotSupportedException by design — this is a deliberately unimplemented mutation, not a bug.","triggerScenarios":"Calling Package.DeletePart on a Package whose container is a SiteOfOriginContainer (i.e. resolving or deleting content that maps to the application's site of origin, e.g. siteOfOrigin:// URIs in an XBAP).","commonSituations":"Code that generically iterates pack URIs and tries to delete source parts; refactoring code that assumed all Package instances are writable ZipPackages; attempting cleanup of site-of-origin resources.","solutions":["Do not delete site-of-origin parts; they represent read-only deployment content.","Guard deletion with a check for the container type or part Uri scheme before calling DeletePart.","Wrap deletion in try/catch for NotSupportedException when dealing with arbitrary packages.","Use a real writable Package (e.g. Package.Open on a .zip) for parts that must be mutable."],"exampleFix":"// before\npackage.DeletePart(partUri);\n// after\nif (package is SiteOfOriginContainer)\n    return; // site-of-origin parts are read-only\npackage.DeletePart(partUri);","handlingStrategy":"try-catch","validationCode":"if (package is SiteOfOriginContainer) return; // deletion unsupported for site-of-origin","typeGuard":"bool IsWritablePackage(Package p) => p is not SiteOfOriginContainer;","tryCatchPattern":"try\n{\n    package.DeletePart(partUri);\n}\ncatch (NotSupportedException)\n{\n    // site-of-origin parts are read-only; skip\n}","preventionTips":["Only mutate packages opened via Package.Open (ZipPackage).","Treat siteOfOrigin:// content as immutable deployment data.","Check container type before generic package mutation code."],"tags":["wpf","packaging","not-supported","read-only"],"backgroundTag":"unsupported-operation","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"}