{"record":{"id":"152d24fe74aebce6","repo":"dotnet/wpf","slug":"sr-assemblyidnegative","errorCode":null,"errorMessage":"SR.AssemblyIdNegative","messagePattern":"SR\\.AssemblyIdNegative","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedBamlSchemaContext.cs","lineNumber":83,"sourceCode":"            {\n                case -1:\n                    result = \"Name\";\n                    break;\n                case -2:\n                    result = \"Uid\";\n                    break;\n                default:\n                    result = null;\n                    break;\n            }\n            return result;\n        }\n\n        internal Baml6Assembly GetKnownBamlAssembly(Int16 assemblyId)\n        {\n            if (assemblyId > 0)\n            {\n                throw new ArgumentException(SR.AssemblyIdNegative);\n            }\n            assemblyId = (short)-assemblyId;\n\n            Baml6Assembly assembly = _knownBamlAssemblies[assemblyId];\n            if (assembly == null)\n            {\n                assembly = CreateKnownBamlAssembly(assemblyId);\n                _knownBamlAssemblies[assemblyId] = assembly;\n            }\n            return assembly;\n        }\n\n        internal Baml6Assembly CreateKnownBamlAssembly(Int16 assemblyId)\n        {\n            Baml6Assembly assembly;\n\n            switch (assemblyId)\n            {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedBamlSchemaContext.cs#L65-L101","documentation":"GetKnownBamlAssembly maps negated BAML assembly ids to known assemblies (ids are stored negative). A zero or positive assemblyId is invalid input, so an ArgumentException with SR.AssemblyIdNegative is thrown. The contract is that only negative encoded ids are accepted; the method negates the value back internally.","triggerScenarios":"Calling GetKnownBamlAssembly with an assemblyId that is 0 or positive, i.e. an id that was not the negated encoding produced by the BAML schema context.","commonSituations":"Off-by-sign bugs when reading BAML records manually; corrupted or hand-crafted BAML streams with a wrong assembly id; tooling that decodes BAML and forgets to negate the id.","solutions":["Pass the id exactly as encoded in BAML (negative); the method negates it internally.","Verify the BAML stream is not corrupted — regenerate it by recompiling the XAML.","If decoding manually, negate the value before calling: GetKnownBamlAssembly((short)-rawId).","Validate the id is < 0 before calling and skip/log otherwise."],"exampleFix":"// before\nvar asm = schemaContext.GetKnownBamlAssembly((short)3); // positive id throws\n// after\nvar asm = schemaContext.GetKnownBamlAssembly((short)-3); // negated BAML-encoded id","handlingStrategy":"validation","validationCode":"if (assemblyId >= 0) throw new ArgumentException($\"BAML assembly ids are stored negated; got {assemblyId}.\");","typeGuard":"bool IsEncodedBamlAssemblyId(short id) => id < 0;","tryCatchPattern":"try { asm = ctx.GetKnownBamlAssembly(id); }\ncatch (ArgumentException) { /* log invalid encoded id; treat stream as corrupt */ }","preventionTips":["Never hand-decode BAML ids; always pass them through as read.","Regenerate BAML with a matching compiler version rather than patching ids."],"tags":["wpf","baml","schema-context","argument"],"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"}