{"record":{"id":"257a491160890377","repo":"dotnet/maui","slug":"xc0040-257a49","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/FontSizeTypeConverter.cs","lineNumber":60,"sourceCode":"\t\t\t\t\t\t\tcontext.Cache,\n\t\t\t\t\t\t\t(\"mscorlib\", \"System\", \"Type\"),\n\t\t\t\t\t\t\tmethodName: \"GetTypeFromHandle\",\n\t\t\t\t\t\t\tparameterTypes: [(\"mscorlib\", \"System\", \"RuntimeTypeHandle\")],\n\t\t\t\t\t\t\tisStatic: true));\n\t\t\t\t\t}\n\t\t\t\t\tyield return Instruction.Create(OpCodes.Call, module.ImportMethodReference(\n\t\t\t\t\t\t\tcontext.Cache,\n\t\t\t\t\t\t\t(\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"Device\"),\n\t\t\t\t\t\t\tmethodName: \"GetNamedSize\",\n\t\t\t\t\t\t\tparameterTypes: [(\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"NamedSize\"), (\"System.Runtime\", \"System\", \"Type\")],\n\t\t\t\t\t\t\tisStatic: true));\n\n\t\t\t\t\tyield break;\n\t\t\t\t}\n#pragma warning restore CS0612 // Type or member is obsolete\n\t\t\t}\n\n\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(double));\n\t\t}\n\t}\n}\n","sourceCodeStart":42,"sourceCodeEnd":64,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/FontSizeTypeConverter.cs#L42-L64","documentation":"XC0040 Conversion thrown by FontSizeTypeConverter when a XAML string is neither a valid invariant-culture double nor a valid NamedSize enum member (Default, Micro, Small, Medium, Large). The converter first attempts a numeric double parse, then falls back to the NamedSize enum. If both fail, the build-time exception is thrown with the target type 'double'.","triggerScenarios":"Setting a font-size-related property (e.g. Label.FontSize) to a string like 'Big', '12pt', '1.5em', or any non-numeric, non-NamedSize value. The NamedSize fallback is obsolete/legacy.","commonSituations":"Using CSS or web-style font size units (pt, px, em, rem) which are not recognized. Using a NamedSize value that does not exist. Relying on NamedSize which is deprecated in newer MAUI versions.","solutions":["Provide a plain numeric double value for an explicit size, e.g. FontSize=\"14\".","Alternatively use a NamedSize enum value: Default, Micro, Small, Medium, or Large (though this API is deprecated).","Remove any unit suffixes — the value must be a bare number or a NamedSize name."],"exampleFix":"<!-- before -->\n<Label FontSize=\"14pt\" />\n\n<!-- after -->\n<Label FontSize=\"14\" />","handlingStrategy":"validation","validationCode":"// Validate a FontSize XAML string before building\nstatic bool IsValidFontSize(string value)\n{\n    if (string.IsNullOrWhiteSpace(value)) return false;\n    value = value.Trim();\n    if (double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out _))\n        return true;\n    return Enum.TryParse<NamedSize>(value, out _);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["FontSize must be a plain number (e.g. '14') or a legacy NamedSize (Default, Micro, Small, Medium, Large).","NamedSize is deprecated — prefer explicit numeric sizes.","Never use web-style units (pt, px, em) in FontSize XAML values."],"tags":["xaml","maui","xamlc","type-converter","fontsize","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}