{"record":{"id":"917fba8edb63386a","repo":"dotnet/maui","slug":"xc0040-917fba","errorCode":"XC0040","errorMessage":"Cannot convert value \"{0}\" to \"{1}\".","messagePattern":"Cannot convert value \"(.+?)\" to \"(.+?)\"\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/NodeILExtensions.cs","lineNumber":142,"sourceCode":"\t\t\tvar typeConverter = bpRef.GetBindablePropertyTypeConverter(context.Cache, module);\n\n\t\t\t//we're gonna SetValue. if the BP type is Nullable, we only need to convert/box to the non-nullable type? why, because the CSC compiler does it like that\n\t\t\tif (targetTypeRef.ResolveCached(context.Cache).FullName == \"System.Nullable`1\")\n\t\t\t\ttargetTypeRef = ((GenericInstanceType)targetTypeRef).GenericArguments[0];\n\n\t\t\treturn node.PushConvertedValue(context, targetTypeRef, typeConverter, pushServiceProvider, boxValueTypes,\n\t\t\t\tunboxValueTypes);\n\t\t}\n\n\t\tstatic T TryFormat<T>(Func<string, T> func, IXmlLineInfo lineInfo, string str)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn func(str);\n\t\t\t}\n\t\t\tcatch (FormatException fex)\n\t\t\t{\n\t\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, lineInfo, fex, str, typeof(T));\n\t\t\t}\n\t\t}\n\n\t\tpublic static IEnumerable<Instruction> PushConvertedValue(this ValueNode node, ILContext context,\n\t\t\tTypeReference targetTypeRef, TypeReference typeConverter, Func<TypeReference[], IEnumerable<Instruction>> pushServiceProvider,\n\t\t\tbool boxValueTypes, bool unboxValueTypes)\n\t\t{\n\t\t\tvar module = context.Body.Method.Module;\n\t\t\tvar knownCompiledTypeConverters = context.Cache.GetKnownCompiledTypeConverters(module);\n\n\t\t\tvar str = (string)node.Value;\n\t\t\t//If the TypeConverter has a ProvideCompiledAttribute that can be resolved, shortcut this\n\t\t\tType compiledConverterType;\n\t\t\tif (typeConverter?.GetCustomAttribute(context.Cache, module, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls.Xaml\", \"ProvideCompiledAttribute\"))?.ConstructorArguments?.First().Value is string compiledConverterName\n\t\t\t\t&& (compiledConverterType = Type.GetType(compiledConverterName)) != null\n\t\t\t\t|| (typeConverter != null && knownCompiledTypeConverters.TryGetValue(typeConverter, out compiledConverterType)))\n\t\t\t{\n\t\t\t\tvar compiledConverter = Activator.CreateInstance(compiledConverterType);","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/NodeILExtensions.cs#L124-L160","documentation":"Thrown by NodeILExtensions.TryFormat when converting a XAML literal string to a target type (via Parse/TryParse-style func) raises a FormatException. The XAML compiler attempts to convert inline literals (numbers, enums, GUIDs, etc.) to the property's type and reports the offending value and target type.","triggerScenarios":"Setting a numeric property to a non-numeric string; an enum property set to an undefined member; a GUID/DateTime property with a malformed literal; locale-specific number separators that Parse rejects.","commonSituations":"Typing a value like Opacity=\"1,5\" in a comma-decimal locale where '.' is expected; misspelling an enum value; passing a string where a typed converter expects a specific format; unit suffixes like '10px' on a double property.","solutions":["Use the literal format the target type's Parse expects (e.g. '.' decimal separator for double).","For enums, use the exact member name (case-sensitive).","Strip units or use a TypeConverter-aware syntax for unitized values.","If the value must be dynamic, bind it rather than inlining a literal."],"exampleFix":"// before\n<Frame Opacity=\"1,5\" />   <!-- comma in invariant culture -->\n// after\n<Frame Opacity=\"1.5\" />","handlingStrategy":"try-catch","validationCode":"// Pre-validate a literal against the target type's Parse (invariant culture)\nstatic bool CanConvert<T>(string literal) {\n    try { _ = (T)System.ComponentModel.TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, literal); return true; }\n    catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"// If you author a custom TypeConverter's compiled path, wrap Parse in TryFormat-style guard\ntry { return func(str); }\ncatch (FormatException fex) {\n    throw new BuildException(BuildExceptionCode.Conversion, lineInfo, fex, str, typeof(T));\n}","preventionTips":["Use the invariant (en-US) literal format: '.' decimals, exact enum names.","Avoid unit suffixes on properties without a TypeConverter for them.","Bind dynamic values instead of inlining literals that need parsing."],"tags":["xaml","xamlc","typeconverter","value-conversion","parsing","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}