{"record":{"id":"4836a52d8eb2d1e0","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"value","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/InheritSystemColorTypeConverter.cs","lineNumber":29,"sourceCode":"    private ColorConverter ColorConverter { get; } = new();\n\n    public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)\n        => sourceType == typeof(string) ||\n           ColorConverter.CanConvertFrom(context, sourceType) ||\n           base.CanConvertFrom(context, sourceType);\n\n    public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(true)] Type? destinationType)\n        => ColorConverter.CanConvertTo(context, destinationType) ||\n           base.CanConvertTo(context, destinationType);\n\n    public override object ConvertFrom(ITypeDescriptorContext? td, System.Globalization.CultureInfo? ci, object? value)\n    {\n        if (value is null)\n        {\n            throw GetConvertFromException(value);\n        }\n\n        string? s = value as string ?? throw new ArgumentNullException(nameof(value));\n        \n        if (string.Equals(s, Inherit, StringComparison.OrdinalIgnoreCase))\n        {\n            return Theme.GetSystemAccentColor() ?? default;\n        }\n\n        return ColorConverter.ConvertFrom(td, ci, s);\n    }\n\n    public override object ConvertTo(ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, Type destinationType)\n    {\n        if (value is Color color &&\n            color != default &&\n            color == Theme.GetSystemAccentColor())\n        {\n            return Inherit;\n        }\n        return ColorConverter.ConvertTo(context, culture, value, destinationType);","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/InheritSystemColorTypeConverter.cs#L11-L47","documentation":"InheritSystemColorTypeConverter is the TypeConverter that lets a Color property accept the literal string \"Inherit\" (or any normal color) in XAML. After the explicit null check, it casts value to string; if value is non-null but not a string (e.g. a Brush, int, or enum), the cast returns null and it throws ArgumentNullException(nameof(value)). The message is slightly misleading: value is not null, it is the wrong type.","triggerScenarios":"The XAML/binding system or a programmatic call passes a non-null, non-string, non-Color object (a SolidColorBrush, an int, an enum) to this converter, where ColorConverter also cannot convert it.","commonSituations":"Binding a non-string source (a Brush or value type) to a Color property wired with this converter; assigning an unrelated object type through a binding after a MaterialDesign upgrade changed converter wiring.","solutions":["Provide the value as a string: \"Inherit\" or a color name/hex such as \"#FF4081\".","Bind the property to a Color or string source rather than a Brush or unrelated type.","If assigning programmatically, call converter.ConvertFrom with a string literal."],"exampleFix":"<!-- before -->\n<md:SomeControl AccentColor=\"{StaticResource MyBrush}\" />\n<!-- after -->\n<md:SomeControl AccentColor=\"Inherit\" />","handlingStrategy":"validation","validationCode":"if (value is not null and not string and not Color)\n    throw new ArgumentException(\"Color value must be a string or Color.\", nameof(value));\n// then call the converter / set the property","typeGuard":"value is string || value is Color","tryCatchPattern":null,"preventionTips":["Bind Color properties to string or Color sources, never Brushes.","Use 'Inherit' or a hex string in XAML for accent colors.","Keep MaterialDesignThemes/MaterialDesignColors versions aligned so converter wiring stays consistent."],"tags":["wpf","xaml","type-converter","color","argument-null"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}