{"record":{"id":"9b5b9afab8c355d2","repo":"dotnet/wpf","slug":"sr-wrongfirstsegment","errorCode":null,"errorMessage":"SR.WrongFirstSegment","messagePattern":"SR\\.WrongFirstSegment","errorType":"exception","errorClass":"UriFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Navigation/BaseUriHelper.cs","lineNumber":274,"sourceCode":"                firstSegment = original.Substring(start, end - start);\n\n                // The resource comes from dll\n                if (firstSegment.EndsWith(COMPONENT, StringComparison.OrdinalIgnoreCase))\n                {\n                    partName = original.Substring(end + 1);\n                    fHasComponent = true;\n                }\n            }\n\n            if (fHasComponent)\n            {\n                string[] assemblyInfo = firstSegment.Split(COMPONENT_DELIMITER);\n\n                int count = assemblyInfo.Length;\n\n                if ((count > 4) || (count < 2))\n                {\n                    throw new UriFormatException(SR.WrongFirstSegment);\n                }\n\n                //\n                // if the uri contains escaping character,\n                // Convert it back to normal unicode string\n                // so that the string as assembly name can be\n                // recognized by Assembly.Load later.\n                //\n                assemblyName = Uri.UnescapeDataString(assemblyInfo[0]);\n\n                for (int i = 1; i < count - 1; i++)\n                {\n                    if (assemblyInfo[i].StartsWith(VERSION, StringComparison.OrdinalIgnoreCase))\n                    {\n                        if (string.IsNullOrEmpty(assemblyVersion))\n                        {\n                            assemblyVersion = assemblyInfo[i].Substring(1);  // Get rid of the leading \"v\"\n                        }","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Navigation/BaseUriHelper.cs#L256-L292","documentation":"BaseUriHelper.GetAssemblyNameAndPart parses the first segment of a pack application URI (the part after 'application:///' containing component segments) and throws UriFormatException(SR.WrongFirstSegment) when the segment count is not between 2 and 4. The URI's first segment must have the form componentname;componentkey;version with an optional extra part.","triggerScenarios":"Passing a pack://application:,,,/ URI whose first segment splits into fewer than 2 or more than 4 semicolon-delimited components, via GetAssemblyAndPartNameFromPackAppUri.","commonSituations":"Malformed pack URIs in XAML or code: wrong number of semicolon-separated assembly parts, typos like 'assembly;;' or extra segments, URIs copied from a different .NET/WPF version with different pack syntax expectations.","solutions":["Correct the pack URI so the first segment has the expected form: componentname;componentkey;version (2-4 semicolon-separated parts).","Use the standard 'pack://application:,,,/AssemblyName;component/Path' syntax without stray semicolons in the assembly portion.","Validate the URI with Uri.TryCreate and inspect the absolute path before handing it to pack URI resolution."],"exampleFix":"// before\nvar uri = new Uri(\"pack://application:,,,/a;b;c;d;e/Win.xaml\", UriKind.Absolute); // 5 segments -> throws\n// after\nvar uri = new Uri(\"pack://application:,,,/MyAssembly;v1.0.0.0;component/Win.xaml\", UriKind.Absolute);","handlingStrategy":"validation","validationCode":"static bool IsValidPackAppFirstSegment(Uri u)\n{\n    if (u == null || !u.IsAbsoluteUri) return false;\n    var seg = u.AbsolutePath.TrimStart('/');\n    var parts = seg.Split(';');\n    return parts.Length >= 2 && parts.Length <= 4;\n}","typeGuard":null,"tryCatchPattern":"try { var name = BaseUriHelper.GetAssemblyAndPartNameFromPackAppUri(uri); }\ncatch (UriFormatException ex) { /* log/repair the pack URI */ }","preventionTips":["Build pack URIs from constants/helpers, not raw string concatenation.","Keep the first segment to the form name[;key][;vversion][;component] (2-4 parts).","Validate with Uri.TryCreate before resolution."],"tags":["wpf","pack-uri","uri-parsing","uriformatexception"],"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"}