{"record":{"id":"efc0cbe969647de7","repo":"dotnet/wpf","slug":"sr-urimustbeabsolute","errorCode":null,"errorMessage":"SR.UriMustBeAbsolute","messagePattern":"SR\\.UriMustBeAbsolute","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs","lineNumber":144,"sourceCode":"\n            lock (_globalLock)\n            {\n                // If the key doesn't exist, it is no op\n                _packages?.Remove(uri);\n            }\n        }\n\n        #endregion Public Methods\n\n        #region Private Methods\n\n        private static void ValidatePackageUri(Uri uri)\n        {\n            ArgumentNullException.ThrowIfNull(uri);\n\n            if (!uri.IsAbsoluteUri)\n            {\n                throw new ArgumentException(SR.UriMustBeAbsolute, nameof(uri));\n            }\n        }\n        \n\n        #endregion Private Methods\n    \n        #region Private Fields\n\n        // We expect to have no more than 10 packages in the store\n        //  per AppDomain for our scenarios\n        // ListDictionary is the best fit for this scenarios; otherwise we should be using\n        // Hashtable. HybridDictionary already has functionality of switching between\n        //  ListDictionary and Hashtable depending on the size of the collection\n        private static HybridDictionary _packages;\n        private static readonly Object _globalLock;\n\n        #endregion Private Fields\n    }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs#L126-L162","documentation":"PackageStore.ValidatePackageUri is the shared guard used by GetPackage, AddPackage, and RemovePackage. It throws ArgumentNullException for a null uri and ArgumentException(SR.UriMustBeAbsolute) when the Uri is relative, because store keys are absolute pack URIs. All three public PackageStore methods funnel through this validation.","triggerScenarios":"Passing a relative Uri (or null) to PackageStore.GetPackage, AddPackage, or RemovePackage.","commonSituations":"Storing pack keys as relative strings like \"myapp:,,,/x\" and constructing Uri without the pack:// scheme; URIs read from config that omit the authority prefix.","solutions":["Pass an absolute pack URI, e.g. new Uri(\"pack://myapp:,,,/\", UriKind.Absolute).","Call PackUriHelper.Create(uriString) to normalize/validate the pack URI before store access.","Guard with uri.IsAbsoluteUri before calling any PackageStore method."],"exampleFix":"// before\nPackageStore.GetPackage(new Uri(\"myapp:,,,/res\")); // ArgumentException\n// after\nPackageStore.GetPackage(new Uri(\"pack://myapp:,,,/res\", UriKind.Absolute));","handlingStrategy":"validation","validationCode":"if (uri == null) throw new ArgumentNullException(nameof(uri));\nif (!uri.IsAbsoluteUri) throw new ArgumentException(\"package URI must be absolute\", nameof(uri));","typeGuard":"static bool IsValidPackageUri(Uri u) => u != null && u.IsAbsoluteUri;","tryCatchPattern":"try { pkg = PackageStore.GetPackage(uri); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(uri)) { uri = new Uri(\"pack://application:,,,\" + uri.OriginalString.TrimStart('/'), UriKind.Absolute); pkg = PackageStore.GetPackage(uri); }","preventionTips":["Always construct store keys with UriKind.Absolute","Normalize pack keys via PackUriHelper.Create","Never pass relative or null URIs to PackageStore APIs"],"tags":["wpf","packaging","packagestore","uri"],"backgroundTag":"invalid-url-format","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"}