dotnet/maui · error · InvalidOperationException
Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> c
Error message
Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> could not be intercepted because the feature has been disabled. Consider removing the DisableMauiAnalyzers property from your project file or set the _MauiBindingInterceptorsSupport property to true instead. What it means
Thrown by the typed (lambda-getter) overload of SetBinding in BindableObjectExtensions when the RuntimeFeature.AreBindingInterceptorsSupported switch is false. This overload is a stub: a Roslyn source generator is expected to intercept the call and rewrite it into a compiled TypedBinding. With interceptors disabled the stub body executes and throws at runtime, because the lambda binding can never be built. The message points at the two MSBuild knobs that gate the switch.
Source
Thrown at src/Controls/src/Core/BindableObjectExtensions.cs:150
/// <param name="source">An object used as the source for this binding. This parameter is optional. Default is <see langword="null" />.</param>
/// <param name="fallbackValue">The value to use instead of the default value for the property, if no specified value exists.</param>
/// <param name="targetNullValue">The value to supply for a bound property when the target of the binding is <see langword="null" />.</param>
/// <exception cref="ArgumentNullException"></exception>
public static void SetBinding<TSource, TProperty>(
this BindableObject self,
BindableProperty targetProperty,
Func<TSource, TProperty> getter,
BindingMode mode = BindingMode.Default,
IValueConverter? converter = null,
object? converterParameter = null,
string? stringFormat = null,
object? source = null,
object? fallbackValue = null,
object? targetNullValue = null)
{
if (!RuntimeFeature.AreBindingInterceptorsSupported)
{
throw new InvalidOperationException($"Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> could not be intercepted because the feature has been disabled. Consider removing the DisableMauiAnalyzers property from your project file or set the _MauiBindingInterceptorsSupport property to true instead.");
}
throw new InvalidOperationException($"Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> was not intercepted.");
}
#nullable disable
public static T GetPropertyIfSet<T>(this BindableObject bindableObject, BindableProperty bindableProperty, T returnIfNotSet)
{
if (bindableObject == null)
return returnIfNotSet;
if (bindableObject.IsSet(bindableProperty))
return (T)bindableObject.GetValue(bindableProperty);
return returnIfNotSet;
}
internal static bool TrySetDynamicThemeColor(View on GitHub (pinned to f377ff1c5e)
Solutions
- Remove <DisableMauiAnalyzers>true</DisableMauiAnalyzer> (or its older spelling) from the .csproj / Directory.Build.props.
- Set <_MauiBindingInterceptorsSupport>true</_MauiBindingInterceptorsSupport> explicitly to force the feature switch on.
- Confirm the project uses the Microsoft.Maui.Controls.Sdk or references the Microsoft.Maui.Controls.SourceGenerators package so the interceptor actually ships.
- If you must keep interceptors off, fall back to the string-path overload: SetBinding(targetProperty, new Binding(nameof(...))).
Example fix
// before myLabel.SetBinding(Label.TextProperty, static vm => vm.Title); // after (when interceptors must stay off) myLabel.SetBinding(Label.TextProperty, new Binding(nameof(MyViewModel.Title)));
Defensive patterns
Strategy: validation
Validate before calling
if (!Microsoft.Maui.Controls.Internals.RuntimeFeature.AreBindingInterceptorsSupported)
{
// do not call the typed SetBinding overload; use the string-path overload
label.SetBinding(Label.TextProperty, new Binding(nameof(MyViewModel.Title)));
} Prevention
- Keep DisableMauiAnalyzers absent from all .props files for projects using typed bindings.
- Prefer BindingBase.Create with a static expression-bodied lambda so the interceptor can rewrite it.
- Document the feature-switch dependency next to any typed-binding helper.
When it happens
Trigger: Calling SetBinding(self, targetProperty, getter => ...) or BindingBase.Create(getter => ...) where the getter is a Func<TSource,TProperty> lambda, in a project where DisableMauiAnalyzers=true or where _MauiBindingInterceptorsSupport has been set to false (or the AppContext switch Microsoft.Maui.RuntimeFeature.AreBindingInterceptorsSupported was turned off).
Common situations: Copying the new typed-binding API into a legacy Xamarin-era project that set DisableMauiAnalyzers; trimming/AOT configs that disabled interceptors; CI builds that differ from local because a Directory.Build.props flips the switch; upgrading to a .NET MAUI version that introduced lambda bindings while an old .props file still disables analyzers.
Related errors
- Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> w
- path cannot be an empty string
- Cannot apply relative binding to {bindObj.GetType().FullName
- Cannot apply relative binding when the target object is null
- Namescopes are not supported. Please enable the feature swit
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/55df46c1ea2f56d3.
Report an issue: GitHub.