unoplatform/uno · error · NotSupportedException

Field modifier 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.).

Solutions

  1. Change the field's accessibility to public, internal, or private.
  2. If the field is inherited and cannot be changed, create a public/internal wrapper property and bind to that instead.
  3. 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

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


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/b749a59b8ac7e3e9. Report an issue: GitHub.

Appendix: 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)