{"record":{"id":"10cb9304096a589c","repo":"dotnet/wpf","slug":"sr-parserbadstring-0-1","errorCode":null,"errorMessage":"SR.ParserBadString: {0} {1}","messagePattern":"SR\\.ParserBadString: (.+?) (.+?)","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecords.cs","lineNumber":2605,"sourceCode":"                // if it can convert.\n                // NOTE:  This is sensitive to changes in the BamlRecordWriter and\n                //        BamlRecordManager code and must be kept in sync with them...\n                converted = serializer.ConvertStringToCustomBinary(bamlBinaryWriter, Value);\n            }\n            else if (SerializerType == typeof(XamlPathDataSerializer))\n            {\n                XamlSerializer serializer = new XamlPathDataSerializer();\n\n                // If we custom serialize this particular value at this point, then see\n                // if it can convert.\n                // NOTE:  This is sensitive to changes in the BamlRecordWriter and\n                //        BamlRecordManager code and must be kept in sync with them...\n                converted = serializer.ConvertStringToCustomBinary(bamlBinaryWriter, Value);\n            }\n\n            if (!converted)\n            {\n                throw new XamlParseException(SR.Format(SR.ParserBadString, Value, ValueType.Name));\n            }\n        }\n\n#if !PBTCOMPILER\n        internal override void Copy(BamlRecord record)\n        {\n            base.Copy(record);\n\n            BamlPropertyCustomWriteInfoRecord newRecord = (BamlPropertyCustomWriteInfoRecord)record;\n            newRecord._valueId = _valueId;\n            newRecord._valueType = _valueType;\n            newRecord._value = _value;\n            newRecord._valueMemberName = _valueMemberName;\n            newRecord._serializerType = _serializerType;\n            newRecord._typeContext = _typeContext;\n        }\n#endif\n","sourceCodeStart":2587,"sourceCodeEnd":2623,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecords.cs#L2587-L2623","documentation":"A string-convertible BAML record (POD/deferrable content record) throws XamlParseException with SR.ParserBadString when its serializer reports ConvertString could not convert the Value to custom binary (converted == false). The record's string value cannot be represented in the BAML binary encoding for its ValueType.","triggerScenarios":"Compiling XAML to BAML where a PODStringRecord's Value cannot be converted by the type's serializer via ConvertStringToCustomBinary/ConvertToString.","commonSituations":"Malformed attribute values in XAML for types with custom string/binary converters (e.g. KeyString, deferrable resource keys), typos in enumerated or specially formatted string values, culture-sensitive string formats.","solutions":["Fix the offending string value in the XAML so the type's converter accepts it (message names the value and expected ValueType)","Check the ValueType converter — ensure the value matches the documented format for that type","Simplify the attribute (e.g. use a plain string key instead of a custom binary-convertible one)","If a valid string still fails, verify the custom serializer/converter is registered and in sync with BamlRecordManager"],"exampleFix":"// before\n<Window x:Key=\"{x:Static bad:key}\" />\n// after: use a converter-compatible value\n<Window x:Key=\"MyWindowKey\" />","handlingStrategy":"validation","validationCode":"// validate the value converts before writing BAML\nif (!canConvert(valueType, attributeValue))\n    throw new XamlParseException($\"Value '{attributeValue}' is not valid for {valueType.Name}\");","typeGuard":"static bool IsValidString(Type targetType, string value) {\n    try { TypeConverter c = TypeDescriptor.GetConverter(targetType); return c != null && c.IsValid(value); }\n    catch { return false; }\n}","tryCatchPattern":"try { CompileXaml(xaml); }\ncatch (XamlParseException ex) {\n    log.Error($\"Bad string attribute in XAML: {ex.Message}\"); throw;\n}","preventionTips":["Validate attribute values against their type converters during development","Keep custom serializers in sync with BamlRecordManager","Use plain string keys where custom binary encoding isn't needed"],"tags":["wpf","xaml","baml","string-conversion"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}