unoplatform/uno · error · InvalidOperationException

Either TypeName or Type must be filled before calling Provid

Error message

Either TypeName or Type must be filled before calling ProvideValue method

What it means

Thrown by TypeExtension.ProvideValue when both Type and TypeName are null. The extension can produce a value only if at least one is set (Type takes precedence and is returned directly; TypeName is resolved via IXamlTypeResolver).

Source

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

			Type = type;
		}

		[ConstructorArgument ("type")]
		[DefaultValue (null)]
		public Type Type { get; set; }
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public string TypeName { get; set; }

		public override object ProvideValue (IServiceProvider serviceProvider)
		{
			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 ()));
			}

View on GitHub (pinned to 0418340488)

Solutions

  1. Set Type (preferred when known) or TypeName before calling ProvideValue.
  2. If using XAML, ensure x:Type arguments are populated, e.g. <x:Type TypeName="local:MyControl"/>.
  3. Add a precondition check before ProvideValue to surface a domain-specific error message.

Example fix

// before
var ext = new TypeExtension();
var v = ext.ProvideValue(sp); // throws

// after
var ext = new TypeExtension { TypeName = "local:MyControl" };
var v = ext.ProvideValue(sp);
Defensive patterns

Strategy: validation

Validate before calling

var ext = new TypeExtension();
// set either Type or TypeName before ProvideValue
if (ext.Type == null && ext.TypeName == null)
    throw new InvalidOperationException("TypeExtension requires Type or TypeName");
var value = ext.ProvideValue(sp);

Type guard

static bool IsTypeExtensionReady(TypeExtension e) => e.Type != null || !string.IsNullOrEmpty(e.TypeName);

Prevention

When it happens

Trigger: Calling ProvideValue on a default-constructed TypeExtension (new TypeExtension()) without assigning either Type or TypeName.

Common situations: Programmatic markup-extension construction that skips initialization; XAML parse paths where the x:Type directive has no operand; partial initialization in factories.

Related errors


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