{"record":{"id":"200cfd85bbb579a1","repo":"dotnet/maui","slug":"xc0040-200cfd","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/ImageSourceTypeConverter.cs","lineNumber":36,"sourceCode":"\t\t\tif (Uri.TryCreate(value, UriKind.Absolute, out Uri uri) && uri.Scheme != \"file\")\n\t\t\t{\n\t\t\t\tyield return Instruction.Create(OpCodes.Ldstr, value);\n\t\t\t\tyield return Instruction.Create(OpCodes.Ldc_I4_1); // (int)UriKind.Absolute is 1\n\t\t\t\tyield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(context.Cache, (\"System\", \"System\", \"Uri\"), parameterTypes: new[] {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(\"mscorlib\", \"System\", \"String\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(\"System\", \"System\", \"UriKind\")}));\n\t\t\t\tyield return Instruction.Create(OpCodes.Call, module.ImportMethodReference(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"ImageSource\"), \"FromUri\", parameterTypes: new[] {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(\"System\", \"System\", \"Uri\")}, isStatic: true));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tyield return Instruction.Create(OpCodes.Ldstr, value);\n\t\t\t\tyield return Instruction.Create(OpCodes.Call, module.ImportMethodReference(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"ImageSource\"), \"FromFile\", parameterTypes: new[] {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(\"mscorlib\", \"System\", \"String\")}, isStatic: true));\n\t\t\t}\n\t\t\tyield break;\n\t\t}\n\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(ImageSource));\n\t}\n}\n","sourceCodeStart":18,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/ImageSourceTypeConverter.cs#L18-L39","documentation":"XC0040 Conversion thrown by ImageSourceTypeConverter when the XAML string value is null or empty. The converter accepts any non-empty, non-whitespace string: if it parses as an absolute non-file URI, it generates ImageSource.FromUri; otherwise it generates ImageSource.FromFile. The only failure condition is a null or empty value.","triggerScenarios":"Setting an ImageSource property to an empty string or a binding/expression that evaluates to empty at XAML compile time. This is rare because most empty bindings are handled before the converter runs, but a literal empty string or whitespace-only attribute triggers it.","commonSituations":"An empty Source attribute on an Image, or a dynamically constructed value that the compiler sees as empty. Accidentally leaving Source=\"\" in markup.","solutions":["Provide a non-empty URI string (e.g. 'https://example.com/image.png') or a file/resource name.","Remove the empty attribute entirely if no image source is intended.","If the value comes from a binding, ensure it resolves to a non-empty string at compile time."],"exampleFix":"<!-- before -->\n<Image Source=\"\" />\n\n<!-- after -->\n<Image Source=\"myimage.png\" />","handlingStrategy":"validation","validationCode":"// Validate an ImageSource XAML string — any non-empty value is accepted\nstatic bool IsValidImageSource(string value)\n    => !string.IsNullOrWhiteSpace(value);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Any non-empty string is accepted: absolute URIs use FromUri, everything else uses FromFile.","Avoid empty Source attributes — remove them if no image is intended.","For compile-time safety, ensure bindings resolve to non-empty strings."],"tags":["xaml","maui","xamlc","type-converter","imagesource","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}