{"record":{"id":"ac5a7824e0e3e8ca","repo":"unoplatform/uno","slug":"an-error-occurred-on-getting-provided-value","errorCode":null,"errorMessage":"An error occurred on getting provided value","messagePattern":"An error occurred on getting provided value","errorType":"exception","errorClass":"XamlObjectWriterException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":283,"sourceCode":"\t\t\tstate.Value = instance;\n\t\t\tstate.IsInstantiated = true;\n\t\t\tobject_states.Push (state);\n\t\t}\n\n\t\tprotected override void OnWriteEndObject ()\n\t\t{\n\t\t\tInitializeObjectIfRequired (false); // this is required for such case that there was no StartMember call.\n\n\t\t\tvar state = object_states.Pop ();\n\t\t\tvar obj = state.Value;\n\t\t\t\n\t\t\tif (obj is MarkupExtension) {\n\t\t\t\ttry {\n\t\t\t\t\tobj = ((MarkupExtension) obj).ProvideValue (service_provider);\n\t\t\t\t} catch (XamlObjectWriterException) {\n\t\t\t\t\tthrow;\n\t\t\t\t} catch (Exception ex) {\n\t\t\t\t\tthrow new XamlObjectWriterException (\"An error occurred on getting provided value\", ex);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t// call this (possibly) before the object is added to parent collection. (bug #3003 also expects this)\n\t\t\tif (state.IsXamlWriterCreated)\n\t\t\t\tsource.OnAfterProperties (obj);\n\t\t\t\n\t\t\tvar nfr = obj as NameFixupRequired;\n\t\t\tif (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.\n\t\t\t\t// actually .NET seems to seek \"parent\" object in its own IXamlNameResolver implementation.\n\t\t\t\tvar pstate = object_states.Peek ();\n\t\t\t\tnfr.ParentType = pstate.Type;\n\t\t\t\tnfr.ParentMember = CurrentMember; // Note that it is a member of the pstate.\n\t\t\t\tnfr.ParentValue = pstate.Value;\n\t\t\t\tpending_name_references.Add ((NameFixupRequired) obj);\n\t\t\t}\n\t\t\telse\n\t\t\t\tStoreAppropriatelyTypedValue (obj, state.KeyValue);","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L265-L301","documentation":"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.","triggerScenarios":"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.","commonSituations":"{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.","solutions":["Inspect the InnerException (and its message, which is appended after the colon) for the real failure.","Fix the resource key, binding path, or extension argument that caused ProvideValue to throw.","Ensure the markup extension receives the IServiceProvider it needs (the writer supplies one; custom invocations may not)."],"exampleFix":"// before: missing resource\n<TextBlock Text=\"{StaticResource MissingBrush}\" />\n// after\n<TextBlock Text=\"{StaticResource DefinedBrush}\" />","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { /* run the writer / load the XAML */ }\ncatch (XamlObjectWriterException ex) when (ex.Message.Contains(\"getting provided value\")) {\n    // ex.InnerException holds the real cause from ProvideValue; surface it.\n    throw new InvalidOperationException(\"Markup extension ProvideValue failed\", ex.InnerException);\n}","preventionTips":["Always inspect InnerException on wrapped writer exceptions — the outer message is generic.","Validate resource keys, binding paths, and x:Static members before relying on the extension.","Unit-test custom markup extensions' ProvideValue in isolation to catch failures early."],"tags":["xaml","markup-extension","inner-exception","object-writer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}