unoplatform/uno · error · NotSupportedException
Field modifier {accessibility} is not supported
Error message
Field modifier {accessibility} is not supported What it means
Thrown by the accessibility-to-string conversion method when a field's Accessibility value does not match Private, Internal, or Public. The switch has a default case that throws NotSupportedException for any other accessibility level (Protected, ProtectedOrInternal, ProtectedAndInternal, etc.).
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs:253
return Accessibility.Private;
}
private string FormatAccessibility(Accessibility accessibility)
{
switch (accessibility)
{
case Accessibility.Private:
return "private";
case Accessibility.Internal:
return "internal";
case Accessibility.Public:
return "public";
default:
throw new NotSupportedException($"Field modifier {accessibility} is not supported");
}
}
private INamedTypeSymbol GetPropertyTypeByOwnerSymbol(INamedTypeSymbol ownerType, string propertyName, int lineNumber, int linePosition, [CallerMemberName] string caller = "")
{
var definition = _metadataHelper.FindPropertyTypeByOwnerSymbol(ownerType, propertyName);
if (definition == null)
{
throw new Exception($"The property {ownerType}.{propertyName} is unknown. Line number: {lineNumber}, Line position: {linePosition}, Caller: {caller}, File: {_fileDefinition.FilePath}");
}
return definition;
}
private ISymbol? FindProperty(XamlMember xamlMember)
{
var type = FindType(xamlMember.DeclaringType);View on GitHub (pinned to 0418340488)
Solutions
- Change the field's accessibility to public, internal, or private.
- If the field is inherited and cannot be changed, create a public/internal wrapper property and bind to that instead.
- Move the field declaration to a context where it can be public/internal.
Example fix
// before
protected string _myValue;
<!-- XAML binds to _myValue -->
// after
public string MyValue { get => _myValue; set => _myValue = value; } Defensive patterns
Strategy: validation
Validate before calling
// Check field accessibility before binding in XAML:
// var fields = typeof(MyPage).GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
// foreach (var f in fields.Where(f => f.IsFamily || f.IsFamilyOrAssembly))
// Console.WriteLine($"Field {f.Name} is {f.Attributes} — change to public/internal/private for XAML"); Prevention
- Use public or internal accessibility for fields bound in XAML.
- Prefer properties over fields for XAML data binding.
- Avoid protected fields in types involved in XAML code generation.
When it happens
Trigger: A field used in XAML code generation (e.g. an x:Bind source field or a named element backing field) has a protected or protected-internal accessibility modifier.
Common situations: A field declared as 'protected' in a base class or partial class is picked up by the XAML generator; code that was refactored from public to protected without updating XAML bindings; an inherited protected field is bound via x:Bind.
Related errors
- The property {ownerType}.{propertyName} is unknown. Line num
- The {0} string passed in the colorString argument is not a r
- Member '{0}' could not be resolved to a static member
- Attempt to set value from read-only property {0}
- Current operation is valid only when the underlying type on
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/b749a59b8ac7e3e9.
Report an issue: GitHub.