{"record":{"id":"55df46c1ea2f56d3","repo":"dotnet/maui","slug":"call-to-setbinding-typeof-tsource-typeof-tpro","errorCode":null,"errorMessage":"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.","messagePattern":"Call to SetBinding<(.+?), (.+?)> 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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableObjectExtensions.cs","lineNumber":150,"sourceCode":"\t\t/// <param name=\"source\">An object used as the source for this binding. This parameter is optional. Default is <see langword=\"null\" />.</param>\n\t\t/// <param name=\"fallbackValue\">The value to use instead of the default value for the property, if no specified value exists.</param>\n\t\t/// <param name=\"targetNullValue\">The value to supply for a bound property when the target of the binding is <see langword=\"null\" />.</param>\n\t\t/// <exception cref=\"ArgumentNullException\"></exception>\n\t\tpublic static void SetBinding<TSource, TProperty>(\n\t\t\tthis BindableObject self,\n\t\t\tBindableProperty targetProperty,\n\t\t\tFunc<TSource, TProperty> getter,\n\t\t\tBindingMode mode = BindingMode.Default,\n\t\t\tIValueConverter? converter = null,\n\t\t\tobject? converterParameter = null,\n\t\t\tstring? stringFormat = null,\n\t\t\tobject? source = null,\n\t\t\tobject? fallbackValue = null,\n\t\t\tobject? targetNullValue = null)\n\t\t{\n\t\t\tif (!RuntimeFeature.AreBindingInterceptorsSupported)\n\t\t\t{\n\t\t\t\tthrow 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.\");\n\t\t\t}\n\n\t\t\tthrow new InvalidOperationException($\"Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> was not intercepted.\");\n\t\t}\n#nullable disable\n\n\t\tpublic static T GetPropertyIfSet<T>(this BindableObject bindableObject, BindableProperty bindableProperty, T returnIfNotSet)\n\t\t{\n\t\t\tif (bindableObject == null)\n\t\t\t\treturn returnIfNotSet;\n\n\t\t\tif (bindableObject.IsSet(bindableProperty))\n\t\t\t\treturn (T)bindableObject.GetValue(bindableProperty);\n\n\t\t\treturn returnIfNotSet;\n\t\t}\n\n\t\tinternal static bool TrySetDynamicThemeColor(","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableObjectExtensions.cs#L132-L168","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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(...)))."],"exampleFix":"// before\nmyLabel.SetBinding(Label.TextProperty, static vm => vm.Title);\n\n// after (when interceptors must stay off)\nmyLabel.SetBinding(Label.TextProperty, new Binding(nameof(MyViewModel.Title)));","handlingStrategy":"validation","validationCode":"if (!Microsoft.Maui.Controls.Internals.RuntimeFeature.AreBindingInterceptorsSupported)\n{\n    // do not call the typed SetBinding overload; use the string-path overload\n    label.SetBinding(Label.TextProperty, new Binding(nameof(MyViewModel.Title)));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["maui","data-binding","source-generators","msbuild","feature-switch"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}