unoplatform/uno · error · XamlObjectWriterException

An error occurred on getting provided value

Error message

An error occurred on getting provided value

What it means

A catch-all wrapper thrown in OnWriteEndObject when a MarkupExtension's ProvideValue call throws any exception that is not already a XamlObjectWriterException. The original exception is attached as InnerException, and its message is the authoritative cause. The text 'An error occurred on getting provided value' is generic by design.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs:283

			state.Value = instance;
			state.IsInstantiated = true;
			object_states.Push (state);
		}

		protected override void OnWriteEndObject ()
		{
			InitializeObjectIfRequired (false); // this is required for such case that there was no StartMember call.

			var state = object_states.Pop ();
			var obj = state.Value;
			
			if (obj is MarkupExtension) {
				try {
					obj = ((MarkupExtension) obj).ProvideValue (service_provider);
				} catch (XamlObjectWriterException) {
					throw;
				} catch (Exception ex) {
					throw new XamlObjectWriterException ("An error occurred on getting provided value", ex);
				}
			}
			
			// call this (possibly) before the object is added to parent collection. (bug #3003 also expects this)
			if (state.IsXamlWriterCreated)
				source.OnAfterProperties (obj);
			
			var nfr = obj as NameFixupRequired;
			if (nfr != null && object_states.Count > 0) { // IF the root object to be written is x:Reference, then the Result property will become the NameFixupRequired. That's what .NET also does.
				// actually .NET seems to seek "parent" object in its own IXamlNameResolver implementation.
				var pstate = object_states.Peek ();
				nfr.ParentType = pstate.Type;
				nfr.ParentMember = CurrentMember; // Note that it is a member of the pstate.
				nfr.ParentValue = pstate.Value;
				pending_name_references.Add ((NameFixupRequired) obj);
			}
			else
				StoreAppropriatelyTypedValue (obj, state.KeyValue);

View on GitHub (pinned to 0418340488)

Solutions

  1. Inspect the InnerException (and its message, which is appended after the colon) for the real failure.
  2. Fix the resource key, binding path, or extension argument that caused ProvideValue to throw.
  3. Ensure the markup extension receives the IServiceProvider it needs (the writer supplies one; custom invocations may not).

Example fix

// before: missing resource
<TextBlock Text="{StaticResource MissingBrush}" />
// after
<TextBlock Text="{StaticResource DefinedBrush}" />
Defensive patterns

Strategy: try-catch

Try / catch

try { /* run the writer / load the XAML */ }
catch (XamlObjectWriterException ex) when (ex.Message.Contains("getting provided value")) {
    // ex.InnerException holds the real cause from ProvideValue; surface it.
    throw new InvalidOperationException("Markup extension ProvideValue failed", ex.InnerException);
}

Prevention

When it happens

Trigger: Any markup extension ({Binding}, {StaticResource}, {x:Static}, {DynamicResource}, or a custom extension) whose ProvideValue throws — e.g. a missing resource key, an invalid binding path, or a custom extension rejecting its arguments.

Common situations: {StaticResource Key} where Key is not defined; custom markup extension with a bug or missing IServiceProvider service; {x:Static} on a nonexistent member; binding against a null data context.

Related errors


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