{"record":{"id":"70bb4fd5382568c0","repo":"dotnet/maui","slug":"xc0040-70bb4f","errorCode":"XC0040","errorMessage":"Cannot convert value \"{0}\" to \"{1}\".","messagePattern":"Cannot convert value \"(.+?)\" to \"(.+?)\"\\.","errorType":"error_code","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs","lineNumber":20,"sourceCode":"using System.Globalization;\nusing Microsoft.Maui.Controls.Build.Tasks;\nusing Microsoft.Maui.Controls.Xaml;\nusing Mono.Cecil.Cil;\nusing static Mono.Cecil.Cil.Instruction;\nusing static Mono.Cecil.Cil.OpCodes;\n\nnamespace Microsoft.Maui.Controls.XamlC\n{\n\tclass ConstraintTypeConverter : ICompiledTypeConverter\n\t{\n\t\tpublic IEnumerable<Instruction> ConvertFromString(string value, ILContext context, BaseNode node)\n\t\t{\n\t\t\tvar module = context.Body.Method.Module;\n\n\t\t\tdouble size;\n\n\t\t\tif (string.IsNullOrEmpty(value) || !double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out size))\n\t\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Compatibility.Constraint));\n\n\t\t\tyield return Create(Ldc_R8, size);\n\t\t\tyield return Create(Call, module.ImportMethodReference(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls.Compatibility\", \"Constraint\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   methodName: \"Constant\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   parameterTypes: new[] { (\"mscorlib\", \"System\", \"Double\") },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   isStatic: true));\n\t\t}\n\t}\n}\n","sourceCodeStart":2,"sourceCodeEnd":30,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs#L2-L30","documentation":"XamlC error XC0040 from ConstraintTypeConverter (Microsoft.Maui.Controls.Compatibility). This compiled converter supports only a single constant double, which it wraps in Constraint.Constant(size). An empty value or any string that is not a double throws XC0040. Relative/factor/multiply constraints are not supported by this string converter.","triggerScenarios":"A Constraint-typed attribute is set to an empty string or a non-numeric value; or an attempt is made to express a relative constraint (e.g. 'relativeToParent' style) as a plain string instead of via the ConstraintExpression markup extension.","commonSituations":"Leaving the attribute empty; typing a formula or unit suffix; confusing constant constraints with relative ones that require {ConstraintExpression ...}.","solutions":["Provide a single numeric constant (e.g. Constraint=\"42\").","For non-constant constraints (relative to parent/sibling, factor, multiply), use the ConstraintExpression markup extension instead of a plain string."],"exampleFix":"<!-- before -->\n<RelativeLayout>\n  <BoxView RelativeLayout.WidthConstraint=\"\" />\n</RelativeLayout>\n\n<!-- after -->\n<RelativeLayout>\n  <BoxView RelativeLayout.WidthConstraint=\"{ConstraintExpression Type=Constant, Constant=100}\" />\n</RelativeLayout>","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["For constant constraints, supply a plain numeric string.","For relative/factor constraints, use the ConstraintExpression markup extension, not a plain string.","Never leave a Constraint-typed attribute empty."],"tags":["xaml","xamlc","relativelayout","constraint","compilation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}