{"record":{"id":"561860fd62e000ed","repo":"microsoft/semantic-kernel","slug":"dictionary-561860","errorCode":null,"errorMessage":"dictionary","messagePattern":"dictionary","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.HuggingFace/Models/HuggingFaceTextGenerationMetadata.cs","lineNumber":69,"sourceCode":"        get => this.GetValueFromDictionary(nameof(this.GeneratedTokens)) as int?;\n        internal init => this.SetValueInDictionary(value, nameof(this.GeneratedTokens));\n    }\n\n    /// <summary>\n    /// Finish reason.\n    /// </summary>\n    public string? FinishReason\n    {\n        get => this.GetValueFromDictionary(nameof(this.FinishReason)) as string;\n        internal init => this.SetValueInDictionary(value, nameof(this.FinishReason));\n    }\n\n    /// <summary>\n    /// Converts a dictionary to a <see cref=\"HuggingFaceChatCompletionMetadata\"/> object.\n    /// </summary>\n    public static HuggingFaceTextGenerationMetadata FromDictionary(IReadOnlyDictionary<string, object?> dictionary) => dictionary switch\n    {\n        null => throw new ArgumentNullException(nameof(dictionary)),\n        HuggingFaceTextGenerationMetadata metadata => metadata,\n        IDictionary<string, object?> metadata => new HuggingFaceTextGenerationMetadata(metadata),\n        _ => new HuggingFaceTextGenerationMetadata(dictionary.ToDictionary(pair => pair.Key, pair => pair.Value))\n    };\n\n    private void SetValueInDictionary(object? value, string propertyName)\n        => this.Dictionary[propertyName] = value;\n\n    private object? GetValueFromDictionary(string propertyName)\n        => this.Dictionary.TryGetValue(propertyName, out var value) ? value : null;\n}\n","sourceCodeStart":51,"sourceCodeEnd":81,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.HuggingFace/Models/HuggingFaceTextGenerationMetadata.cs#L51-L81","documentation":"Thrown by HuggingFaceTextGenerationMetadata.FromDictionary when the dictionary argument is null. Same pattern as the other metadata FromDictionary methods: converting a raw response dictionary into typed metadata; null is a programming error. Message 'dictionary' is the parameter name.","triggerScenarios":"Calling HuggingFaceTextGenerationMetadata.FromDictionary(null) or forwarding a null dictionary from an upstream response.","commonSituations":"Custom text-generation pipelines forwarding possibly-null metadata; refactors removing non-null guarantees.","solutions":["Null-check before calling FromDictionary.","Use an empty dictionary for absent metadata.","Guarantee the upstream source produces non-null dictionaries."],"exampleFix":"// before\nvar meta = HuggingFaceTextGenerationMetadata.FromDictionary(raw);  // raw may be null\n\n// after\nvar meta = raw is null ? null : HuggingFaceTextGenerationMetadata.FromDictionary(raw);","handlingStrategy":"validation","validationCode":"static HuggingFaceTextGenerationMetadata? SafeMeta(IReadOnlyDictionary<string,object?>? d)\n    => d is null ? null : HuggingFaceTextGenerationMetadata.FromDictionary(d);","typeGuard":"static bool IsNonNullDict(IReadOnlyDictionary<string,object?>? d) => d is not null;","tryCatchPattern":null,"preventionTips":["Null-check before calling FromDictionary.","Use an empty dictionary for absent metadata.","Ensure upstream sources produce non-null dictionaries."],"tags":["huggingface","metadata","null-argument"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}