{"record":{"id":"62d6922b86fbb34a","repo":"dotnet/wpf","slug":"sr-packagespecificreferencetagmustbeunique","errorCode":null,"errorMessage":"SR.PackageSpecificReferenceTagMustBeUnique","messagePattern":"SR\\.PackageSpecificReferenceTagMustBeUnique","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs","lineNumber":1179,"sourceCode":"        private void ValidateReferences(IEnumerable references, bool allowPackageSpecificReferences)\n        {\n            Debug.Assert(references != null);\n\n            bool packageReferenceFound = false;\n            TransformChain currentTransformChain;\n\n            foreach (Reference currentReference in references)\n            {\n                //As per the OPC spec, Uri attribute in Reference elements MUST refer using fragment identifiers\n                //This implies that Uri cannot be absolute.\n                if (currentReference.Uri.StartsWith(\"#\", StringComparison.Ordinal))\n                {\n                    //As per the OPC spec, there MUST be exactly one package specific reference to the \n                    //package specific <Object> element \n                    if (string.Equals(currentReference.Uri, XTable.Get(XTable.ID.OpcLinkAttrValue), StringComparison.Ordinal))\n                    {\n                        if (!allowPackageSpecificReferences)\n                            throw new ArgumentException(SR.PackageSpecificReferenceTagMustBeUnique);\n\n                        //If there are more than one package specific tags\n                        if (packageReferenceFound)\n                            throw new XmlException(SR.MoreThanOnePackageSpecificReference);\n                        else\n                            packageReferenceFound = true;\n                    }\n\n                    currentTransformChain = currentReference.TransformChain;\n\n                    for(int j=0; j<currentTransformChain.Count; j++)\n                    {\n                        //As per the OPC spec, only two transforms are supported for the reference tags\n                        if (!IsValidXmlCanonicalizationTransform(currentTransformChain[j].Algorithm))\n                            throw new XmlException(SR.UnsupportedTransformAlgorithm);\n                    }\n                }\n                else","sourceCodeStart":1161,"sourceCodeEnd":1197,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs#L1161-L1197","documentation":"ValidateReferences walks the signature's <Reference> elements. Per the OPC spec there must be exactly one package-specific reference (URI equal to the OpcLinkAttrValue) pointing at the package <Object>. If such a reference is encountered where package-specific references are not allowed, ArgumentException(SR.PackageSpecificReferenceTagMustBeUnique) is thrown.","triggerScenarios":"Verifying a signature or adding custom object tags when a <Reference> with the package-specific URI appears in a reference set that forbids it — e.g. a part-level reference list contains a reference to the package Object instead of a real part URI.","commonSituations":"Custom signing code that adds a package-specific reference into the wrong reference group; signatures crafted by third-party tools that mix part references and package Object references; verifying signatures not produced by the OPC-aware .NET signer.","solutions":["Re-sign the package with PackageDigitalSignatureManager.Sign so references are structured per the OPC profile.","Remove the package-specific <Reference> from the part-level reference set; it must exist only in the allowed group.","Inspect the signature's SignedXml Reference URIs and fix the one using the OpcLink value.","Reject/strip non-conformant third-party signatures before verification."],"exampleFix":"// before: package-specific reference among part refs\n<Reference URI=\"#idPackageObject\">...</Reference>  <!-- inside part manifest refs -->\n// after: re-sign correctly\nvar dsm = new PackageDigitalSignatureManager(pkg);\ndsm.Sign(toSign, cert); // places the package Object reference per OPC spec","handlingStrategy":"validation","validationCode":"// Scan part-level references for the package-specific URI before Verify\nvar opcUri = \"#idPackageObject\"; // XTable.OpcLinkAttrValue\nvar badRefs = doc.SelectNodes(\"//*[local-name()='Reference']/@URI\")\n    .Cast<XmlAttribute>()\n    .Where(a => a.Value == opcUri);\n// only the allowed group may contain it; >0 elsewhere is invalid","typeGuard":"static bool NoOpcLinkInPartRefs(IEnumerable<string> partRefUris, string opcUri) =>\n    !partRefUris.Contains(opcUri);","tryCatchPattern":"try { dsm.VerifySignatures(true); }\ncatch (ArgumentException ex) { /* misplaced package-specific reference — reject/re-sign */ }","preventionTips":["Never add a package Object reference into part-level reference lists.","Use PackageDigitalSignatureManager.Sign to build references correctly.","Validate third-party signatures' Reference URIs before verification.","Strip and re-sign non-conformant signatures."],"tags":["wpf","xml-signature","opc","reference"],"backgroundTag":"invalid-argument-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"}