unoplatform/uno · error · InvalidOperationException

serviceProvider does not provide IXamlTypeResolver service.

Error message

serviceProvider does not provide IXamlTypeResolver service.

What it means

Thrown by TypeExtension.ProvideValue when the service provider does not return an IXamlTypeResolver from GetService. The resolver is mandatory to map the TypeName string to a System.Type; without it string-based type resolution cannot proceed.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Windows.Markup/TypeExtension.cs:87

			if (Type != null)
			{
				return Type;
			}

			if (TypeName == null)
			{
				throw new InvalidOperationException ("Either TypeName or Type must be filled before calling ProvideValue method");
			}

			if (serviceProvider == null) // it can be null when Type is supplied.
			{
				throw new ArgumentNullException ("serviceProvider");
			}

			var p = serviceProvider.GetService (typeof (IXamlTypeResolver)) as IXamlTypeResolver;
			if (p == null)
			{
				throw new InvalidOperationException ("serviceProvider does not provide IXamlTypeResolver service.");
			}

			var ret = p.Resolve (TypeName);
			if (ret == null)
			{
				throw new InvalidOperationException (String.Format (CultureInfo.InvariantCulture, "Type '{0}' is not resolved as a valid type by the type resolver '{1}'.", TypeName, p.GetType ()));
			}

			return ret;
		}
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Use the standard XamlObjectWriter/XamlXmlReader context which supplies IXamlTypeResolver.
  2. In tests, provide a fake provider returning a IXamlTypeResolver for the requested service type.
  3. Set the Type property to bypass resolver-based resolution entirely.

Example fix

// before
var ext = new TypeExtension { TypeName = "local:MyControl" };
var v = ext.ProvideValue(minimalProvider); // throws

// after
var ext = new TypeExtension { TypeName = "local:MyControl" };
var v = ext.ProvideServiceWith<XamlTypeResolver>(resolver => ext.ProvideValue(ctx));
Defensive patterns

Strategy: validation

Validate before calling

public static bool HasTypeResolver(IServiceProvider sp)
    => sp?.GetService(typeof(IXamlTypeResolver)) is IXamlTypeResolver;

if (!HasTypeResolver(sp))
    throw new InvalidOperationException("IXamlTypeResolver missing");
var value = new TypeExtension { TypeName = "local:Foo" }.ProvideValue(sp);

Type guard

static bool HasTypeResolver(IServiceProvider sp)
    => sp?.GetService(typeof(IXamlTypeResolver)) is IXamlTypeResolver;

Prevention

When it happens

Trigger: Calling ProvideValue with a provider whose GetService(typeof(IXamlTypeResolver)) returns null, e.g. a minimal mock or a context that only supplies other services.

Common situations: Custom XAML pipelines that omit the type resolver; test stubs; reusing a provider from a different markup extension that does not need type resolution.

Related errors


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