{"record":{"id":"a801ab6d66782277","repo":"dotnet/wpf","slug":"notallowedpackageuri","errorCode":null,"errorMessage":"NotAllowedPackageUri","messagePattern":"NotAllowedPackageUri","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs","lineNumber":95,"sourceCode":"        /// The package will not be automatically replaced within the store.\n        /// </remarks>\n        public static void AddPackage(Uri uri, Package package)\n        {\n            ValidatePackageUri(uri);\n\n            // There are well-known package types that are only for internal use (for resource loading)\n            //  (i.e. ResourceContainer - \"application://\" and SiteOriginContainer - \"siteoforigin://\"\n            // Adding packages with such key uri will have no effect on PackWebRequest since\n            //  they cannot be overriden. So, calling this method with such key Uris should be prevented \n            //  However, uri.Equal cannot be used here since the key Uris are used as a pack Uri form and\n            //  only PackUriHelper.ComparePackUri can do the proper comparison of pack Uris.\n\n            Uri packUri = PackUriHelper.Create(uri);\n       \n            if (PackUriHelper.ComparePackUri(packUri, BaseUriHelper.PackAppBaseUri) == 0 ||\n                PackUriHelper.ComparePackUri(packUri, BaseUriHelper.SiteOfOriginBaseUri) == 0)\n            {\n                throw new ArgumentException(SR.NotAllowedPackageUri, nameof(uri));\n            }\n\n            ArgumentNullException.ThrowIfNull(package);\n\n            lock (_globalLock)\n            {\n                if (_packages == null)\n                {\n                    _packages = new HybridDictionary(2);\n                }\n\n                if (_packages.Contains(uri))\n                {\n                    throw new InvalidOperationException(SR.PackageAlreadyExists);\n                }\n                \n                _packages.Add(uri, package);\n            }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs#L77-L113","documentation":"PackageStore.AddPackage rejects pack URIs that collide with the framework's reserved base URIs. PackUriHelper.Create normalizes the input, and if the resulting pack URI equals BaseUriHelper.PackAppBaseUri (pack://application:,,,) or SiteOfOriginBaseUri (pack://siteoforigin:,,,), ArgumentException(SR.NotAllowedPackageUri) is thrown. Applications may not register a Package under the URIs WPF itself uses for application resources and site-of-origin files.","triggerScenarios":"Calling PackageStore.AddPackage with a Uri that normalizes to pack://application:,,, or pack://siteoforigin:,,, (or trivially different casing/equivalent forms).","commonSituations":"Attempting to override the application's own resource package; registering a container with an empty or root pack URI built from misconfigured base strings.","solutions":["Use a distinct custom pack authority, e.g. pack://myapp:,,,/..., instead of application: or siteoforigin:.","Check the URI against BaseUriHelper.PackAppBaseUri / SiteOfOriginBaseUri before calling AddPackage.","If you intended to load application resources, use Application resource APIs rather than PackageStore."],"exampleFix":"// before\nPackageStore.AddPackage(new Uri(\"pack://application:,,,/\"), pkg); // throws\n// after\nPackageStore.AddPackage(new Uri(\"pack://myapp:,,,/\"), pkg);","handlingStrategy":"validation","validationCode":"Uri packUri = PackUriHelper.Create(uri);\nif (PackUriHelper.ComparePackUri(packUri, BaseUriHelper.PackAppBaseUri) == 0 ||\n    PackUriHelper.ComparePackUri(packUri, BaseUriHelper.SiteOfOriginBaseUri) == 0)\n    throw new ArgumentException(\"reserved pack URI\", nameof(uri));","typeGuard":null,"tryCatchPattern":"try { PackageStore.AddPackage(uri, pkg); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(uri)) { /* use a custom authority like pack://myapp:,,, */ throw; }","preventionTips":["Never register packages under application: or siteoforigin: authorities","Use a custom authority for add-in packages","Normalize with PackUriHelper.Create before comparing URIs"],"tags":["wpf","packaging","packagestore","reserved-uri"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}