unoplatform/uno · error · InvalidOperationException

serviceProvider does not implement IXamlNameResolver

Error message

serviceProvider does not implement IXamlNameResolver

What it means

InvalidOperationException thrown by Bind.ProvideValue (System.Xaml, ported from Mono) when the supplied IServiceProvider does not return an IXamlNameResolver from GetService. Bind resolves its Path against the XAML name table, so a provider lacking the name resolver cannot fulfill the request. This indicates the wrong service context (not a real XAML object-writer context).

Source

Thrown at src/SourceGenerators/System.Xaml/System.Windows.Markup/Bind.cs:41

		[ConstructorArgument ("path")]
		public string Path { get; set; }

		public override object ProvideValue (IServiceProvider serviceProvider)
		{
			if (serviceProvider == null)
			{
				throw new ArgumentNullException ("serviceProvider");
			}

			if (Path == null)
			{
				throw new InvalidOperationException ("Name property is not set");
			}

			var r = serviceProvider.GetService (typeof (IXamlNameResolver)) as IXamlNameResolver;
			if (r == null)
			{
				throw new InvalidOperationException ("serviceProvider does not implement IXamlNameResolver");
			}

			var ret = r.Resolve (Path);
			if (ret == null)
			{
				ret = r.GetFixupToken (new string [] { Path }, true);
			}

			return ret;
		}
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Use the service provider from a real XAML object writer, which supplies IXamlNameResolver.
  2. In tests, make GetService(typeof(IXamlNameResolver)) return a working IXamlNameResolver implementation.
  3. Confirm the host pipeline wires the name resolver before invoking markup extensions.

Example fix

// before
var sp = new StubProvider(); // GetService returns null for IXamlNameResolver
bind.ProvideValue(sp);

// after
var sp = new ServiceProviderWithResolver(nameResolver);
bind.ProvideValue(sp);
Defensive patterns

Strategy: type-guard

Validate before calling

static bool ProviderHasNameResolver(IServiceProvider sp) => sp.GetService(typeof(IXamlNameResolver)) is IXamlNameResolver;

Type guard

static bool IsXamlContext(IServiceProvider sp) => sp?.GetService(typeof(IXamlNameResolver)) is IXamlNameResolver;

Try / catch

try { return bind.ProvideValue(sp); } catch (InvalidOperationException ex) when (ex.Message.Contains("IXamlNameResolver")) { throw new InvalidOperationException("Bind must run inside a XAML object-writer context."); }

Prevention

When it happens

Trigger: Passing a service provider that does not implement/return IXamlNameResolver — e.g. a stub provider in tests or a non-XAML hosting environment.

Common situations: Unit-test providers that only implement some services, a custom markup-extension host that does not expose the name resolver, or calling ProvideValue outside the XAML object-writer pipeline.

Related errors


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