{"record":{"id":"bbe137c42dcdb604","repo":"PrismLibrary/Prism","slug":"valuetargetprovider-targetobject-is-not-supported","errorCode":null,"errorMessage":"{valueTargetProvider.TargetObject} is not supported","messagePattern":"(.+?) is not supported","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Xaml/TargetAwareExtensionBase.cs","lineNumber":87,"sourceCode":"    /// <param name=\"serviceProvider\">The service provider for the markup extension.</param>\n    /// <returns>The value to set on the property where the extension is applied.</returns>\n    /// <exception cref=\"ArgumentException\">Thrown if the service provider does not provide an <see cref=\"IProvideValueTarget\"/>.</exception>\n    /// <exception cref=\"Exception\">Thrown if the target object is not supported.</exception>\n    T IMarkupExtension<T>.ProvideValue(IServiceProvider serviceProvider)\n    {\n        var valueTargetProvider = serviceProvider.GetService<IProvideValueTarget>();\n\n        if (valueTargetProvider == null)\n            throw new ArgumentException(Resources.ServiceProviderDidNotHaveIProvideValueTarget);\n\n        TargetElement = valueTargetProvider.TargetObject as VisualElement;\n\n        //this is handling the scenario of the extension being used within the EventToCommandBehavior\n        if (TargetElement is null && valueTargetProvider.TargetObject is BehaviorBase<BindableObject> behavior)\n            TargetElement = behavior.AssociatedObject as VisualElement;\n\n        if (TargetElement is null)\n            throw new Exception($\"{valueTargetProvider.TargetObject} is not supported\");\n\n        if (TargetElement.TryGetParentPage(out var page))\n            Page = page;\n        else\n            TargetElement.Behaviors.Add(new ElementParentedCallbackBehavior(() => Page = TargetElement.GetParentPage()));\n\n        return ProvideValue(serviceProvider);\n    }\n\n    /// <summary>\n    /// Provides the value for the markup extension (non-generic implementation).\n    /// </summary>\n    /// <param name=\"serviceProvider\">The service provider for the markup extension.</param>\n    /// <returns>The value to set on the property where the extension is applied.</returns>\n    object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) =>\n        ((IMarkupExtension<T>)this).ProvideValue(serviceProvider);\n\n    /// <summary>","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Xaml/TargetAwareExtensionBase.cs#L69-L105","documentation":"Prism's XAML markup extensions (e.g. Bind, ViewModelLocator) need to resolve the target element they are applied to in order to find the parent page. ProvideValue throws this exception when the service provider does not yield a supported target (neither a BindableElement nor a Behavior's AssociatedObject), so the extension has no element context to work with.","triggerScenarios":"Using an extension such as x:Bind-style Prism markup extension in a context where IProvideValueTarget.TargetObject is neither a bindable VisualElement nor a BehaviorBase<BindableObject> (e.g. applied to a resource dictionary entry, a Setter value, or a non-VisualElement target). Also occurs when the extension is used inside a behavior whose AssociatedObject is not a VisualElement.","commonSituations":"Applying the extension in a Style Setter or DataTrigger where there is no target element; using it inside custom behaviors that do not derive from BehaviorBase<BindableObject>; platform-specific layouts where the target object is a different wrapper type.","solutions":["Move the markup extension so it is applied directly to a bindable VisualElement property, not a Style/Setter or resource value.","If used inside a behavior, ensure the behavior derives from BehaviorBase<BindableObject> and its AssociatedObject is a VisualElement.","Wrap usage in OnPlatform/OnIdiom only at the element property level, keeping the extension attached to an element.","If the element is attached later, rely on the ElementParentedCallbackBehavior fallback by ensuring TargetElement is resolvable at ProvideValue time."],"exampleFix":"<!-- before -->\n<Style TargetType=\"Label\">\n  <Setter Property=\"Text\" Value=\"{prism:Bind Name}\" />\n</Style>\n<!-- after -->\n<Label Text=\"{prism:Bind Name}\" />","handlingStrategy":"validation","validationCode":"if (targetObject is VisualElement || targetObject is BehaviorBase<BindableObject>)\n    myExtension.Apply();\nelse\n    throw new InvalidOperationException($\"{targetObject} is not supported\");","typeGuard":"bool IsSupportedTarget(object target) => target is VisualElement || target is BehaviorBase<BindableObject> b && b.AssociatedObject is VisualElement;","tryCatchPattern":null,"preventionTips":["Apply Prism markup extensions directly on element properties, never inside Style Setters or resources.","Only use extensions within behaviors deriving from BehaviorBase<BindableObject>.","Test XAML pages on all target platforms to catch provider differences."],"tags":["xaml","maui","markup-extension"],"backgroundTag":"unsupported-operation","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}