dotnet/maui · error · InvalidOperationException

Member '{member.MemberName}' with inaccessible accessor must

Error message

Member '{member.MemberName}' with inaccessible accessor must have MemberType and ContainingType populated.

What it means

An internal source-generator invariant in BindingSourceGen. When a compiled binding path contains a member whose getter or setter is inaccessible (non-public), the generator emits an unsafe accessor and requires PathParser to have populated MemberType and ContainingType metadata for that member. This InvalidOperationException fires only if that metadata is missing, signalling a coordination gap between PathParser and BindingCodeWriter rather than a user mistake.

Source

Thrown at src/Controls/src/BindingSourceGen/BindingCodeWriter.cs:428

			
			Unindent();
			Append('}');
		}

		private void AppendUnsafeAccessors(BindingInvocationDescription binding)
		{
			// Append unsafe accessors as local methods for members with inaccessible accessors
			var membersWithInaccessibleAccessors = binding.Path.OfType<MemberAccess>().Where(m => m.HasInaccessibleAccessor);

			foreach (var member in membersWithInaccessibleAccessors)
			{
				AppendBlankLine();

				// Members with inaccessible accessors must have MemberType and ContainingType populated
				// by PathParser during source analysis
				if (member.MemberType == null || member.ContainingType == null)
				{
					throw new InvalidOperationException($"Member '{member.MemberName}' with inaccessible accessor must have MemberType and ContainingType populated.");
				}

				if (member.Kind == AccessorKind.Field)
				{
					AppendUnsafeFieldAccessor(member.MemberName, member.MemberType.GlobalName, member.ContainingType.GlobalName);
				}
				else if (member.Kind == AccessorKind.Property)
				{
					bool isLastPart = member.Equals(binding.Path.Last());
					bool needsGetterForLastPart = binding.RequiresAllUnsafeGetters;

					if (member.IsGetterInaccessible && (!isLastPart || needsGetterForLastPart))
					{
						// we don't need the unsafe getter if the item is the very last part of the path
						// because we don't need to access its value while constructing the handlers array
						AppendUnsafePropertyGetAccessors(member.MemberName, member.MemberType.GlobalName, member.ContainingType.GlobalName);
					}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Make the bound member's accessor public if the type is yours, which bypasses the unsafe-accessor code path entirely.
  2. Reproduce with the minimal binding and file a Maui issue, since this is a generator invariant violation.
  3. Ensure Maui SDK/package versions are consistent across projects to avoid generator/analysis mismatches.
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Binding to a property or field whose accessor is private/internal/protected, in a case where PathParser could not capture the member's type and declaring type (e.g. symbol info unavailable across assembly boundaries, partial generics, or a newer Maui version).

Common situations: Binding to a member with non-public accessors located in another assembly; source-generator/analysis version skew; binding to a type whose symbol metadata is incomplete during generation.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/0df7b6e3ef7ba744. Report an issue: GitHub.