{"record":{"id":"01212530ada7c273","repo":"dotnet/machinelearning","slug":"throw-new-argumentnullexception-nameof-ids","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(ids));","messagePattern":"throw new ArgumentNullException\\(nameof\\(ids\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.Tokenizers/Model/BPETokenizer.cs","lineNumber":785,"sourceCode":"\n        /// <summary>\n        /// Decode the given ids, back to a String.\n        /// </summary>\n        /// <param name=\"ids\">The list of ids that we want to decode.</param>\n        /// <returns>The decoded string.</returns>\n        public override string Decode(IEnumerable<int> ids) => Decode(ids, considerSpecialTokens: true);\n\n        /// <summary>\n        /// Decode the given ids, back to a String.\n        /// </summary>\n        /// <param name=\"ids\">The list of ids that we want to decode.</param>\n        /// <param name=\"considerSpecialTokens\">Indicate whether to consider special tokens or not.</param>\n        /// <returns>The decoded string.</returns>\n        public string Decode(IEnumerable<int> ids, bool considerSpecialTokens)\n        {\n            if (ids is null)\n            {\n                throw new ArgumentNullException(nameof(ids));\n            }\n\n            if (ByteLevel)\n            {\n                return DecodeByteLevel(ids, considerSpecialTokens);\n            }\n\n            ValueStringBuilder sb = new ValueStringBuilder();\n\n            foreach (int id in ids)\n            {\n                if (_specialTokensReverse?.TryGetValue(id, out string? token) is true)\n                {\n                    if (considerSpecialTokens)\n                    {\n                        sb.Append(token);\n                    }\n                    continue;","sourceCodeStart":767,"sourceCodeEnd":803,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.Tokenizers/Model/BPETokenizer.cs#L767-L803","documentation":"The string-returning Decode overload requires a non-null sequence of token IDs. A null ids argument is rejected immediately with ArgumentNullException because there is no meaningful decode target. Empty sequences are allowed and decode to an empty string.","triggerScenarios":"Calling BpeTokenizer.Decode(IEnumerable<int> ids, bool considerSpecialTokens) with ids == null, typically when the variable holding generated token IDs was never assigned or a decode path ran after a failed encode returned null.","commonSituations":"Pipelines where model output IDs are null on error but the code decodes unconditionally; deserialized objects with a null Ids property.","solutions":["Ensure the IDs collection is initialized (e.g. Array.Empty<int>()) before decoding.","Check the source of the IDs for a null-producing error path and handle it before decoding.","Coalesce null to an empty sequence if decoding nothing is acceptable."],"exampleFix":"// before\nstring text = tokenizer.Decode(ids, considerSpecialTokens: false); // ids is null\n// after\nstring text = tokenizer.Decode(ids ?? (IEnumerable<int>)Array.Empty<int>(), considerSpecialTokens: false);","handlingStrategy":"validation","validationCode":"if (ids is null) throw new InvalidOperationException(\"No token IDs to decode; encoding step failed.\");","typeGuard":"bool HasIds(IEnumerable<int>? ids) => ids is not null;","tryCatchPattern":"try { text = tokenizer.Decode(ids, false); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"ids\") { text = string.Empty; /* surface upstream failure */ }","preventionTips":["Use non-nullable IEnumerable<int> types so the compiler flags null paths.","Check encode results for failure before decoding.","Default to Array.Empty<int>() instead of null."],"tags":["csharp","null-argument","decoding"],"backgroundTag":"null-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}