dotnet/maui · error · InvalidOperationException
Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> w
Error message
Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> was not intercepted. What it means
Thrown by the same typed SetBinding stub, but AFTER the feature switch check passed: AreBindingInterceptorsSupported is true, yet the call was still not rewritten by the source generator. It means the interceptor was enabled in config but never actually executed against this call site, so the stub ran unmodified. This is a build-pipeline defect, not a runtime config mistake.
Source
Thrown at src/Controls/src/Core/BindableObjectExtensions.cs:153
/// <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(
this BindableObject bindableObject,
string resourceKey,
BindableProperty bindableProperty,View on GitHub (pinned to f377ff1c5e)
Solutions
- Rebuild cleanly (delete obj/bin) so the source generator runs against the current call site.
- Ensure the calling project is a MAUI app/library (uses Microsoft.Maui.Controls.Sdk) and not a generic library that lacks the generator reference.
- Simplify the getter to a single expression-bodied lambda with no captured locals, e.g. static vm => vm.Title.
- Verify Microsoft.Maui.Controls and the source-generator package are the same version.
- If the call site can't be intercepted, switch to the string-path Binding overload.
Example fix
// before (block-bodied / capturing lambda - not interceptable)
myLabel.SetBinding(Label.TextProperty, vm => { return vm.Title ?? "-"; });
// after (expression-bodied, interceptable)
myLabel.SetBinding(Label.TextProperty, static vm => vm.Title); Defensive patterns
Strategy: validation
Validate before calling
// Before relying on the typed overload, confirm the generator ran by checking the // compiled assembly for the generated interceptor method via reflection at test time. // At the call site, keep lambdas expression-bodied and static: label.SetBinding(Label.TextProperty, static vm => vm.Title);
Prevention
- Use only expression-bodied static lambdas as getters.
- Reference the same Microsoft.Maui.Controls version for runtime and source generator.
- Run a clean build after touching binding call sites so the interceptor re-runs.
When it happens
Trigger: Using the lambda SetBinding/Create overload inside a project type the MAUI source generator does not target (e.g. a plain netstandard library, a unit test assembly, or a multi-targeting config where the generator assembly isn't loaded); the lambda expression shape is one the interceptor can't pattern-match (e.g. a block-bodied lambda or one capturing locals); an SDK mismatch where the generator package version differs from the runtime.
Common situations: Calling SetBinding with a lambda from a shared library that is not a MAUI app project; upgrading only part of the MAUI packages so the generator and runtime are out of sync; using block-bodied lambdas or method-group conversions instead of expression-bodied getters; incremental-build cache holding a stale generation.
Related errors
- Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> c
- path cannot be an empty string
- Cannot apply relative binding to {bindObj.GetType().FullName
- Cannot apply relative binding when the target object is null
- Call to Create<{typeof(TSource)}, {typeof(TProperty)}> could
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/3c64bb7677970b52.
Report an issue: GitHub.