{"record":{"id":"0947ede0a54766fe","repo":"XINCGer/Unity3DTraining","slug":"key-is-null","errorCode":null,"errorMessage":"Key is null","messagePattern":"Key is null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Collections/MapField.cs","lineNumber":317,"sourceCode":"        bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)\n        {\n            if (item.Key == null)\n            {\n                throw new ArgumentException(\"Key is null\", \"item\");\n            }\n            LinkedListNode<KeyValuePair<TKey, TValue>> node;\n            if (map.TryGetValue(item.Key, out node) &&\n                EqualityComparer<TValue>.Default.Equals(item.Value, node.Value.Value))\n            {\n                map.Remove(item.Key);\n                node.List.Remove(node);\n                return true;\n            }","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Collections/MapField.cs#L299-L335","documentation":"The explicit ICollection<KeyValuePair<TKey,TValue>>.Remove implementation throws ArgumentException when the Key of the pair being removed is null. This is a generic null-input guard: a null key can never match any entry, so the library rejects it upfront instead of performing a lookup.","triggerScenarios":"Calling the ICollection<KeyValuePair<TKey,TValue>>.Remove interface method (e.g. through a MapField typed as that interface) with a KeyValuePair whose Key property is null.","commonSituations":"Removing entries through an ICollection view of the map where the pair was default-initialized (default(KeyValuePair<TKey,TValue>) has a null key for reference-type keys); iterating data with missing keys and attempting removal.","solutions":["Guard with if (item.Key == null) before calling Remove and skip or log such entries.","Use MapField.Remove(TKey key) or ContainsKey first, ensuring a non-null key.","Ensure pairs are fully constructed rather than default(KeyValuePair<TKey,TValue>) before removal."],"exampleFix":"if (pair.Key != null) { collection.Remove(pair); } // or use mapField.Remove(pair.Key) which handles lookups directly.","handlingStrategy":"validation","validationCode":"if (item.Key == null) throw new ArgumentNullException(nameof(item));","typeGuard":"bool HasKey<TK,TV>(KeyValuePair<TK,TV> p) => p.Key != null;","tryCatchPattern":"try { collection.Remove(item); } catch (ArgumentException ex) { /* ex.ParamName == \"item\" */ }","preventionTips":["Never pass default-initialized key/value pairs into ICollection.Remove.","Validate keys for null before map operations on maps with reference-type keys."],"tags":["protobuf","csharp","null-argument"],"backgroundTag":"null-argument","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}