unoplatform/uno · error · XamlGenerationException
Unable to find 'MethodName' property on '{symbol}'
Error message
Unable to find 'MethodName' property on '{symbol}' What it means
Thrown by BuildXamlTypeConverterLiteralValue when a type decorated with [CreateFromString] does not have a 'MethodName' named argument on the attribute. The generator reads the MethodName named argument to find the conversion method; if it is absent or null, this XamlGenerationException fires.
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:2274
}
private bool IsCustomMarkupExtensionType(XamlType? xamlType, bool allowExtensionSuffix = true) =>
// Determine if the type is a custom markup extension
GetMarkupExtensionType(xamlType, allowExtensionSuffix) != null;
private bool IsXamlTypeConverter(INamedTypeSymbol? symbol)
{
return symbol?.GetAttributes().Any(a => a.AttributeClass?.Equals(Generation.CreateFromStringAttributeSymbol.Value, SymbolEqualityComparer.Default) == true) == true;
}
private string BuildXamlTypeConverterLiteralValue(INamedTypeSymbol? symbol, string memberValue, bool includeQuotations, IXamlLocation location)
{
var attributeData = symbol.FindAttribute(Generation.CreateFromStringAttributeSymbol.Value);
var targetMethod = attributeData?.NamedArguments.FirstOrDefault(kvp => kvp.Key == "MethodName").Value.Value?.ToString();
if (targetMethod == null)
{
throw new XamlGenerationException($"Unable to find 'MethodName' property on '{symbol}'", location);
}
// Since the MethodName value can simply be the name of the method
// without its full path, example: nameof(MyConversionMethod), we must
// make sure to fully qualify the method name with its namespace
var fullyQualifiedOwnerType = !targetMethod.Contains('.')
? $"{symbol?.GetFullyQualifiedTypeIncludingGlobal()}.{targetMethod}"
: GetGlobalizedTypeName(targetMethod);
var literalValue = default(string);
if (includeQuotations)
{
// Return a string that contains the code which calls the "conversion" function with the member value
literalValue = "{0}(\"{1}\")".InvariantCultureFormat(fullyQualifiedOwnerType, memberValue);
}
else
{
// Return a string that contains the code which calls the "conversion" function with the member value.View on GitHub (pinned to 0418340488)
Solutions
- Add MethodName to the [CreateFromString] attribute, pointing to the static method that performs string-to-type conversion.
- Ensure the method name is correct and the method exists as a public static method on the type.
- Follow the existing pattern from other [CreateFromString]-decorated types in the codebase.
Example fix
// before
[CreateFromString]
public class MyType { ... }
// after
[CreateFromString(MethodName = nameof(Parse))]
public class MyType
{
public static MyType Parse(string value) { ... }
} Defensive patterns
Strategy: validation
Validate before calling
// Verify [CreateFromString] has MethodName before using the type in XAML:
// var attr = typeof(MyType).GetCustomAttribute<CreateFromStringAttribute>();
// if (attr == null || string.IsNullOrEmpty(attr.MethodName))
// Console.WriteLine("[CreateFromString] must specify MethodName"); Prevention
- Always set MethodName when decorating a type with [CreateFromString].
- Ensure the named method is public, static, and takes a single string parameter.
- Copy the full attribute pattern from existing type-converter types in the codebase.
When it happens
Trigger: A type is decorated with [CreateFromString] but the MethodName property of the attribute is not set, or the attribute instance is malformed — e.g. [CreateFromString] with no arguments, or with other named arguments but not MethodName.
Common situations: A custom XAML type converter type was decorated with [CreateFromString] incompletely; the attribute was copied from an example without filling in MethodName; the attribute definition changed and MethodName is no longer defaulted.
Related errors
- context
- Value must be non-null string.
- Conversion from type {0} is not supported
- Conversion to type {0} is not supported
- Cannot cast object '{0}' to string
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/9ff3438e9524d547.
Report an issue: GitHub.