{"record":{"id":"9709821024a8148b","repo":"dotnet/BenchmarkDotNet","slug":"the-value-value-is-not-assignable-to-characteri","errorCode":null,"errorMessage":"The value {value} is not assignable to {characteristic} property.","messagePattern":"The value (.+?) is not assignable to (.+?) property\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Characteristics/CharacteristicObject.cs","lineNumber":91,"sourceCode":"\n        private void AssertIsNonFrozenRoot()\n        {\n            AssertNotFrozen();\n            AssertIsRoot();\n        }\n\n        private static void AssertIsAssignable(Characteristic characteristic, object? value)\n        {\n            if (ReferenceEquals(value, Characteristic.EmptyValue) || ReferenceEquals(value, null))\n            {\n                if (characteristic.HasChildCharacteristics)\n                    throw new ArgumentNullException(characteristic.Id);\n\n                return;\n            }\n\n            if (!characteristic.CharacteristicType.GetTypeInfo().IsInstanceOfType(value))\n                throw new ArgumentException(\n                    $\"The value {value} is not assignable to {characteristic} property.\",\n                    characteristic.Id);\n        }\n        #endregion\n\n        #region Properties\n\n        private CharacteristicObject? Owner { get; set; }\n\n        protected CharacteristicObject OwnerOrSelf => Owner ?? this;\n\n        public bool Frozen => Owner?.Frozen ?? frozen;\n\n        protected virtual bool IsPropertyBag => false;\n\n        public bool HasChanges => GetCharacteristicsWithValues().Any(c => c.IsPresentableCharacteristic());\n        #endregion\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Characteristics/CharacteristicObject.cs#L73-L109","documentation":"AssertIsAssignable validates that a value being stored on a characteristic is an instance of the characteristic's declared type (characteristicType). If it is not, ArgumentException is thrown with the characteristic Id as the param name. A separate branch throws ArgumentNullException when a null/EmptyValue is assigned to a characteristic that has child characteristics.","triggerScenarios":"Assigning a value whose runtime type does not match the characteristic's declared type (e.g. a string into an int characteristic), assigning null to a composite/child-bearing characteristic, or a mis-typed generic characteristic constructed via reflection.","commonSituations":"Programmatically building characteristics with mismatched generics, deserializing config values into the wrong CLR type, or copy/merge logic that moves values between characteristics of different declared types.","solutions":["Check characteristic.CharacteristicType.IsInstanceOfType(value) before assigning, exactly as the assertion does.","Convert/coerce the value to the characteristic's declared type before setting it.","For composite characteristics, never assign null; set sub-values individually instead.","Validate types at the boundary where external data enters the characteristic system."],"exampleFix":"// before\ncharacteristic[job] = value; // value is wrong type\n\n// after\nif (!characteristic.CharacteristicType.IsInstanceOfType(value))\n    value = Convert.ChangeType(value, characteristic.CharacteristicType);\ncharacteristic[job] = value;","handlingStrategy":"validation","validationCode":"if (!characteristic.CharacteristicType.IsInstanceOfType(value))\n    value = Convert.ChangeType(value, characteristic.CharacteristicType);\ncharacteristic[obj] = value;","typeGuard":"static bool IsAssignable(Characteristic c, object? v)\n    => v is null ? !c.HasChildCharacteristics : c.CharacteristicType.IsInstanceOfType(v);","tryCatchPattern":"try { characteristic[obj] = value; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not assignable\"))\n{\n    // coerce value to characteristic.CharacteristicType and retry, or reject input\n}","preventionTips":["Validate the value type at the boundary where external data enters the characteristic system.","Never assign null to a composite (child-bearing) characteristic; set sub-values individually.","Keep generic characteristic types consistent with the values you feed them."],"tags":["characteristics","type-mismatch","validation","argument"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}